Top Banner
Kubernetes 101 and F un | ContainerCon E urope 2016 | created wi th and by @LeanderReimer 1
35

Kubernetes 101 and Fun

Feb 14, 2017

Download

Data & Analytics

QAware GmbH
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Kubernetes 101 and Fun

Kubernetes 101and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 1

Page 2: Kubernetes 101 and Fun

About me

Mario-Leander ReimerChief Technologist, QAware [email protected]

twitter://@LeanderReimerhttp://github.com/lreimerhttp://speakerdeck.com/lreimerhttp://www.qaware.de

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 2

Page 3: Kubernetes 101 and Fun

Code and article series are here ...

4 https://github.com/qaware/cloud-native-zwitscher/

4 http://www.qaware.de/fileadmin/userupload/QAware-Cloud-Native-Artikelserie-JavaMagazin-1.pdf

4 http://www.qaware.de/fileadmin/userupload/QAware-Cloud-Native-Artikelserie-JavaMagazin-2.pdf

4 http://www.qaware.de/fileadmin/userupload/QAware-Cloud-Native-Artikelserie-JavaMagazin-3.pdf

4 http://www.qaware.de/fileadmin/userupload/QAware-Cloud-Native-Artikelserie-JavaMagazin-4.pdf

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 3

Page 4: Kubernetes 101 and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 4

Page 5: Kubernetes 101 and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 5

Page 6: Kubernetes 101 and Fun

Design principles for Cloud Native Applications

4 Design for Performance: responsive; concurrency; efficiency.

4 Design for Automation: automate dev tasks & ops tasks.

4 Design for Resiliency: fault-tolerant; self-healing.

4 Design for Elasticity: dynamically scale; be reactive.

4 Design for Delivery: short roundtrips; automated delivery.

4 Design for Diagnosability: cluster-wide logs, traces, metrics.

4 The Twelve-Factor App Principles (https://12factor.net)

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 6

Page 7: Kubernetes 101 and Fun

Cloud Native Stack required!

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 7

Page 8: Kubernetes 101 and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 8

Page 9: Kubernetes 101 and Fun

Cloud Native Stack using Kubernetes.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 9

Page 10: Kubernetes 101 and Fun

Kubernetes 101

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 10

Page 11: Kubernetes 101 and Fun

Local or Cloud setup of Kubernetes

echo "- Use Vagrant for local K8s setup"export KUBERNETES_PROVIDER=vagrantexport NUM_NODES=1

echo "- The default provider is GCE"export KUBERNETES_PROVIDER=gceexport KUBE_GCE_ZONE=europe-west1-dexport NUM_NODES=4

echo "- Another possible provider is AWS"export KUBERNETES_PROVIDER=awsexport KUBE_AWS_ZONE=eu-central-1aexport NODE_SIZE=t2.small

curl -sS https://get.k8s.io | bash

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 11

Page 12: Kubernetes 101 and Fun

Overview of Kubernetes Architecture

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 12

Page 13: Kubernetes 101 and Fun

Main Kubernetes concepts

4 Services are an abstraction for a logical set of Pods.

4 Pods are the smallest deployable units of computing.

4 Deployments provide declarative updates for Pods and RCs.

4 Replica Sets ensure specified number of Pods are running.

4 Labels are key/value pairs attached to objects used for identification.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 13

Page 14: Kubernetes 101 and Fun

Deployment definition as YAMLapiVersion: extensions/v1beta1kind: Deploymentmetadata: name: hello-worldspec: replicas: 1 template: metadata: labels: tier: web spec: containers: - name: hello-world image: "nginx" ports: - containerPort: 80

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 14

Page 15: Kubernetes 101 and Fun

Service definition as YAML

apiVersion: v1kind: Servicemetadata: name: hello-world labels: tier: webspec: # use NodePort here to be able to access the port on each node # use LoadBalancer for external load-balanced IP if supported type: NodePort ports: - port: 80 selector: tier: web

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 15

Page 16: Kubernetes 101 and Fun

Hello World with Kubernetes

$ kubectl cluster-info$ kubectl get nodes

$ kubectl run hello-world --image=nginx --replicas=1 --port=80$ kubectl expose deployment hello-world

$ kubectl get deployments,services,pods$ kubectl describe pod [NAME]$ kubectl delete deployment hello-world

$ kubectl create -f nginx.yml

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 16

Page 17: Kubernetes 101 and Fun

Demo time.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 17

Page 18: Kubernetes 101 and Fun

The Cloud Native Zwitscher Showcase

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 18

Page 19: Kubernetes 101 and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 19

Page 20: Kubernetes 101 and Fun

The source code.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 20

Page 21: Kubernetes 101 and Fun

Dockerize it!

4 Know your base image!!!

4 The Alpine image is too thin for K8s + Spring.

4 You need Bash, DNS and Java.

4 Use a Server JRE.

4 Better build your own image.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 21

Page 22: Kubernetes 101 and Fun

Example Dockerfile for Zwitscher Service

FROM qaware-oss-docker-registry.bintray.io/base/alpine-k8s-ibmjava8:8.0-3.10MAINTAINER QAware GmbH <[email protected]>

RUN mkdir -p /opt/zwitscher-service

COPY build/libs/zwitscher-service-1.1.0.jar /opt/zwitscher-service/zwitscher-service.jarCOPY src/main/docker/zwitscher-service.* /opt/zwitscher-service/

RUN chmod 755 /opt/zwitscher-service/zwitscher-service.*

EXPOSE 8080

CMD /opt/zwitscher-service/zwitscher-service.sh

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 22

Page 23: Kubernetes 101 and Fun

Build, test, tag and push Docker images.

...$ docker built -t zwitscher-service:1.1.0 .

$ docker-compose up

...$ docker tag zwitscher-service:1.1.0 \ qaware-oss-docker-registry.bintray.io/zwitscher/zwitscher-service...$ docker push qaware-oss-docker-registry.bintray.io/zwitscher/zwitscher-service

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 23

Page 24: Kubernetes 101 and Fun

Kubernetize: single or multi-container pods?

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 24

Page 25: Kubernetes 101 and Fun

Possible variation using K8s infrastructure.

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 25

Page 26: Kubernetes 101 and Fun

Define a deployment per container.apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: zwitscher-servicespec: replicas: 1 template: metadata: labels: zwitscher: service spec: containers: - name: zwitscher-service image: "qaware-oss-docker-registry.bintray.io/zwitscher/zwitscher-service:1.1.0" ports: - containerPort: 8080 env: - name: EUREKA_HOST value: zwitscher-eureka

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 26

Page 27: Kubernetes 101 and Fun

Define a service per deployment.

apiVersion: v1kind: Servicemetadata: name: zwitscher-service labels: zwitscher: servicespec: # use NodePort here to be able to access the port on each node # use LoadBalancer for external load-balanced IP if supported type: NodePort ports: - port: 8080 selector: zwitscher: service

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 27

Page 28: Kubernetes 101 and Fun

Be careful using resource constraints.

resources: # required resources for a Pod to be started requests: memory: "128Mi" cpu: "250m"

# the Pod will be restarted if limits are exceeded limits: memory: "192Mi" cpu: "500m"

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 28

Page 29: Kubernetes 101 and Fun

Use liveness and readiness probes with Actuator.

livenessProbe: httpGet: path: /admin/health port: 8080 initialDelaySeconds: 90 timeoutSeconds: 30

readinessProbe: httpGet: path: /admin/info port: 8080 timeoutSeconds: 30

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 29

Page 30: Kubernetes 101 and Fun

Use Retry mechanism for fail-fast behavior.# bootstrap.ymlspring: application: name: zwitscher-service cloud: config: enabled: true failFast: true retry: initialInterval: 1500 maxInterval: 5000 maxAttempts: 5 multiplier: 1.5 discovery: enabled: true serviceId: ZWITSCHER-CONFIG

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 30

Page 31: Kubernetes 101 and Fun

Deployment time!

$ kubectl create -f zwitscher-eureka/k8s-zwitscher-eureka.yml$ kubectl create -f zwitscher-config/k8s-zwitscher-config.yml$ kubectl create -f zwitscher-service/k8s-zwitscher-service.yml$ kubectl create -f zwitscher-board/k8s-zwitscher-board.yml$ kubectl create -f zwitscher-edge/k8s-zwitscher-edge.yml$ kubectl create -f zwitscher-monitor/k8s-zwitscher-monitor.yml

$ kubectl get deployments,pods,services

$ kubectl delete -f k8s-zwitscher.yml

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 31

Page 32: Kubernetes 101 and Fun

Let's have some fun!

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 32

Page 33: Kubernetes 101 and Fun

The Kubepad in action

4 A MIDI controller

4 Display deployments and pods

4 Scale deployments

4 Written in fancy Kotlin

4 Also works for DC/OS

4 https://github.com/qaware/kubepad

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 33

Page 34: Kubernetes 101 and Fun

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 34

Page 35: Kubernetes 101 and Fun

Q & A

| ContainerCon Europe 2016 | created with ☁ and ☕ by @LeanderReimer 35