K u be r ne t es 101 a n d F un | C ontain e rCon E urope 20 1 6 | c - - PowerPoint PPT Presentation

k u be r ne t es 101 a n d f un
SMART_READER_LITE
LIVE PREVIEW

K u be r ne t es 101 a n d F un | C ontain e rCon E urope 20 1 6 | c - - PowerPoint PPT Presentation

K u be r ne t es 101 a n d F un | C ontain e rCon E urope 20 1 6 | c reated wi t h a n d by @L eander R eimer 1 A b ou t m e M ario -L eander R eimer C hief T echnol o gist , Q Aware G mbH m ario -l eander .r eimer @q aware .d e t witter


slide-1
SLIDE 1

Kubernetes 101 and Fun

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

slide-2
SLIDE 2

About me

Mario-Leander Reimer Chief Technologist, QAware GmbH mario-leander.reimer@qaware.de twitter://@LeanderReimer http://github.com/lreimer http://speakerdeck.com/lreimer http://www.qaware.de

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

slide-3
SLIDE 3

Code and article series are here ...

4 https://github.com/qaware/cloud-native-zwitscher/ 4 http://www.qaware.de/fjleadmin/userupload/QAware-Cloud-Native- Artikelserie-JavaMagazin-1.pdf 4 http://www.qaware.de/fjleadmin/userupload/QAware-Cloud-Native- Artikelserie-JavaMagazin-2.pdf 4 http://www.qaware.de/fjleadmin/userupload/QAware-Cloud-Native- Artikelserie-JavaMagazin-3.pdf 4 http://www.qaware.de/fjleadmin/userupload/QAware-Cloud-Native- Artikelserie-JavaMagazin-4.pdf

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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

Design principles for Cloud Native Applications

4 Design for Performance: responsive; concurrency; effjciency. 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.

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

slide-7
SLIDE 7

Cloud Native Stack required!

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

Cloud Native Stack using Kubernetes.

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

slide-10
SLIDE 10

Kubernetes 101

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

slide-11
SLIDE 11

Overview of Kubernetes Architecture

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

slide-12
SLIDE 12

Main Kubernetes concepts

4 Services are an abstraction for a logical set of Pods. 4 Pods are the smallest deployable units

  • f computing.

4 Deployments provide declarative updates for Pods and RCs. 4 Replica Sets ensure specifjed number

  • f Pods are running.

4 Labels are key/value pairs attached to

  • bjects used for identifjcation.

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

slide-13
SLIDE 13

Deployment defjnition as JSON

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: hello-world spec: replicas: 1 template: metadata: labels: tier: web spec: containers:

  • name: hello-world

image: "nginx:alpine" ports:

  • containerPort: 80

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

slide-14
SLIDE 14

Service defjnition as JSON

apiVersion: v1 kind: Service metadata: name: hello-world labels: tier: web spec: # 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 14

slide-15
SLIDE 15

Local or Cloud setup of Kubernetes

echo "- Use Vagrant for local K8s setup" export KUBERNETES_PROVIDER=vagrant export NUM_NODES=1 echo "- The default provider is GCE" export KUBERNETES_PROVIDER=gce export KUBE_GCE_ZONE=europe-west1-d export NUM_NODES=4 echo "- Another possible provider is AWS" export KUBERNETES_PROVIDER=aws export KUBE_AWS_ZONE=eu-central-1a export NODE_SIZE=t2.small curl -sS https://get.k8s.io | bash

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

slide-16
SLIDE 16

Hello World with Kubernetes

$ kubectl cluster-info $ kubectl get nodes $ kubectl run hello-world --image=nginx:alpine --replicas=1 --port=80 $ kubectl expose deployment hello-world --type="NodePort" $ kubectl get deployments,pods $ kubectl describe pod [NAME] $ kubectl delete deployment hello-world $ kubectl create -f nginx.yml

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

slide-17
SLIDE 17

Demo time.

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

slide-18
SLIDE 18

The Cloud Native Zwitscher Showcase

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

The source code.

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

Example Dockerfjle for Zwitscher Service

FROM qaware-oss-docker-registry.bintray.io/base/debian8-jre8 MAINTAINER QAware GmbH <qaware-oss@qaware.de> RUN mkdir -p /opt/zwitscher-service COPY build/libs/zwitscher-service-1.0.1.jar /opt/zwitscher-service/zwitscher-service.jar COPY src/main/docker/zwitscher-service.* /opt/zwitscher-service/ RUN chmod 755 /opt/zwitscher-service/zwitscher-service.* EXPOSE 8761 ENTRYPOINT exec /opt/zwitscher-service/zwitscher-service.sh

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

slide-23
SLIDE 23

Build, test, tag and push Docker images.

... $ docker built -t zwitscher-service:1.0.1 . $ docker-compose up ... $ docker tag zwitscher-service:1.0.1 \ 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

slide-24
SLIDE 24

Kubernetize: single or multi-container pods?

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

slide-25
SLIDE 25

Possible variation using K8s infrastructure.

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

slide-26
SLIDE 26

Defjne a deployment per container.

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zwitscher-service spec: replicas: 1 template: metadata: labels: zwitscher: service spec: containers:

  • name: zwitscher-service

image: "qaware-oss-docker-registry.bintray.io/zwitscher/zwitscher-service:1.0.1" ports:

  • containerPort: 8080

env:

  • name: EUREKA_HOST

value: zwitscher-eureka

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

slide-27
SLIDE 27

Defjne a service per deployment.

apiVersion: v1 kind: Service metadata: name: zwitscher-service labels: zwitscher: service spec: # 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

slide-28
SLIDE 28

Be careful using resource constraints.

resources: requests: memory: "128Mi" cpu: "250m" limits: memory: "192Mi" cpu: "500m"

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

slide-29
SLIDE 29

Use liveness probes on Actuator endpoints.

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

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

slide-30
SLIDE 30

Use Retry mechanism for fail-fast behavior.

# bootstrap.yml spring: 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

slide-31
SLIDE 31

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

slide-32
SLIDE 32

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 32

slide-33
SLIDE 33

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

slide-34
SLIDE 34

Let's have some fun!

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

slide-35
SLIDE 35

Q & A

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