68
Workshop Resources Code: https://github.com/beekpr/public-workshops Slides: https://tinyurl.com/yc2uo3wk Make sure minikube and kubectl is setup (labs/1-setup-cluster.md has some instructions)

Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Workshop Resources

Code: https://github.com/beekpr/public-workshopsSlides:https://tinyurl.com/yc2uo3wk

Make sure minikube and kubectl is setup(labs/1-setup-cluster.md has some instructions)

Page 2: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes WorkshopDeploy your applications like a boss

Page 3: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 4: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

What is Kubernetes?

• Kubernetes is essentially a cluster operating system

• Just like an operating system it has:٠ Kernel

⦿ Scheduler (plays tetris with resources)⦿ ABI (How userspace interacts with kernel)

٠ Userspace⦿ Run processes

Page 5: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Cluster Architecture

• One to several master nodes (provide kernel like services)

• A store of state (etcd)• One to several normal nodes (provide userspace

like services)

Page 6: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

What is Kubernetes?

Master Node

Node 1

Node 2

Node 3

Master

Node 1

Node 2

Node 3

Page 7: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Master Components

• kube-apiserver• kube-controller-manager• kube-scheduler

Page 8: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Master Components

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Page 9: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Node Components

• Applies to master nodes as well• Kubelet agent• Container Runtime Interface (CRI) e.g. docker

Page 10: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Node Components

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

Page 11: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Where can I run kubernetes

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

Page 12: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

How do I use kubernetes

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

Client

Page 13: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubectl is one client

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

kubectl

Page 14: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubectl is one client

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

kubectl

$ kubectl run test --rm -i --tty --image ubuntu -- bash

Page 15: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Basic Concepts

Master Node

Node 1

Node 2

Node 3

ControllerAPI

Scheduler

Kubelet

Kubelet

Kubelet

Kubelet

kubectl

$ kubectl run test --rm -i --tty --image ubuntu -- bash

test

Page 16: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Basic Concepts

• Kubernetes Objects• Namespace• Pod• ConfigMaps and Secrets• Service

Page 17: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Objects

• Persistent entities• Represent state of your cluster• Declarative• Normally specified and returned in YAML format• Loosely coupled

Page 18: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Objects

• Fields٠ apiVersion٠ kind٠ metadata

⦿ name⦿ (namespace)⦿ (labels)

٠ spec/data

apiVersion: v1kind: Podmetadata: name: test-pod namespace: default labels: app=pod env=testspec: containers: - name: container image: busybox command: ['sh', '-c', 'echo Hello World']

Page 19: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Labels• Metadata with semantic meaning• Arbitrary key value pairs• Used as a group mechanism

apiVersion: v1kind: Podmetadata: name: test-pod namespace: default labels: app=pod env=testspec: containers: - name: container image: busybox command: ['sh', '-c', 'echo Hello World']

Page 20: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Namespace

• Way of partitioning cluster, grouping related entities together

• Most Kubernetes objects exist within a namespace (Namespace is an exception as it creates a namespace)

• Let's have a look at our minikube cluster

Page 21: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Namespace - Exercise• List all namespaces

٠ kubectl get namespaces• Describe the default namespace

٠ kubectl describe namespace default• Get yaml representation of default namespace

٠ kubectl get namespace default -o yaml• Create a namespace

٠ kubectl create namespace demo• Get all entities which exist in namespace kube-system

٠ kubectl get all --namespace kube-system• Figure out the current context and cluster

٠ kubectl config get-contexts

Page 22: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Pod

• Smallest schedulable unit in kubernetes• Has a unique IP (all ports available)• Collection of tightly coupled containers (1 or

more)٠ Can share volumes٠ Talk to each other over local interface٠ Scheduled to same physical node

• Should think of them as disposable

Page 23: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Pod - Exercise• Lets do:

٠ labs/2-kubectl.md٠ labs/3-pods.md

• Pods٠ kubectl get pod some-name -o yaml٠ kubectl explain pod.spec

(for description of fields)

Namespace: default

Namespace: kube-system

Page 24: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Pod - Exercise• Lets do:

٠ labs/2-kubectl.md٠ labs/3-pods.md

• Pods٠ kubectl explain pod.spec

(for description of fields)

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Namespace: kube-system

Page 25: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Configuration• Configmaps and secrets allow you to inject configuration into your pods• They can be exposed as

٠ either environment variable٠ file on container filesystem

• Useful for customising containers for different environments٠ Development٠ Production

• Useful for porting existing apps to kubernetes

Page 26: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

ConfigurationapiVersion: v1kind: ConfigMapmetadata: name: some-name namespace: defaultspec: index.html: | <html> ... </html> version: "latest”

Page 27: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

ConfigurationapiVersion: v1kind: ConfigMapmetadata: name: some-name namespace: defaultspec: index.html: | <html> ... </html> version: "latest"

...spec: containers: - name: nginx env: - name: VERSION valueFrom: configMapKeyRef: name: some-name key: version volumeMounts: - name: html mountPath: /etc/nginx/html ... volumes: - name: nginx configMap: name: some-name items: - key: "index.html" path: "index.html"

Page 28: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Configuration - Exercise• Lets do:

٠ labs/5-configuration.md• Pods

٠ kubectl explain configmap٠ kubectl explain secret

(for description of fields)

Namespace: default

Namespace: kube-system

Page 29: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Service• Pods are often short-lived, as such we don’t want to keep track of them, at the

same time we want a way to use them٠ Sounds like DNS

• Services provide this abstraction, they give us a way to٠ Group pods based on labels٠ Route traffic from port on service to port on pod (can be different)

• They provide (for lifetime of service)٠ A unique persistent cluster IP٠ DNS resolution٠ Port resolution

• Have different types:٠ ClusterIP, Loadbalancer, ExternalName

Page 30: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Servicekind: Service

apiVersion: v1

metadata:

name: "demo-app"

spec:

selector:

app: "demo-app"

ports:

- protocol: "TCP"

port: 80

targetPort: 80

type: ClusterIP

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Pod: demo-appapp=demo-app

Service: demo-app

app=demo-app

Page 31: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Service - Exercise• Lets do:

٠ labs/5-services.md• Service

٠ kubectl explain service.spec(for description of fields)

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Pod: demo-appapp=demo-app

Service: demo-app

app=demo-app

Page 32: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Kubernetes Advanced Concepts

• Deployments• (Persistent Volumes)• (Statefulset)• (Daemonset)• (Job)• (Custom Resource Definition (CRD))

Page 33: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Deployments

• Allow us to ensure X many instances of pod are running

• Allow us to control how pods are updated via specifying strategy type

• Works via control loop٠ Observe cluster state -> Different from expected -> Act to

return state to expected state

Page 34: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Deployments

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Deployment: demo

Namespace: default

Pod: demo-appapp=demo-app

Node 2

Deployment: demo

Page 35: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Deployments

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Deployment: demo

Namespace: default

Pod: demo-appapp=demo-app

Node 2

Deployment: demo

Page 36: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Deployments

Namespace: default

Pod: demo-appapp=demo-app

Node 1

Deployment: demo

Pod: demo-appapp=demo-app

Page 37: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Deployments - Exercise• Lets do:

٠ labs/6-deployments.md• Pods

٠ kubectl explain deployments.spec(for description of fields)

Namespace: default

Namespace: kube-system

apiVersion: apps/v1kind: Deploymentmetadata: name: demo labels: app: demo-appspec: replicas: 2 selector: matchLabels: app: demo-app template: metadata: ... same as pod metadata ... spec: ... same as pod spec ...

Page 38: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Questions

Jason Brownbridge <jason at beekeeper.io>

Page 39: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Docker WorkshopDeploy your code like a boss

Page 40: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 41: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 42: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

C++pythonJavaJavaScript

Page 43: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 44: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 45: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 46: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Machine setup

Automation...

Linux service files

Page 47: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 48: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Worked on my machine

Dependency Errors

App Updates

Different Environments

Page 49: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 50: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

What is Docker?

• Software container platform٠ Docker daemon٠ Docker CLI

• Any App, Language, or Stack• Awesome Developer Experience• App Isolation

Page 51: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Docker

• Main docker artefacts:٠ Images٠ Containers

• Docker is using a layered architecture

Page 52: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Images

• A blueprint for a container• Is never running• Is instantiated to create containers• Layered and cached

Page 53: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Containers

• Instance of Image• A running program• Can be running/stopped

• Should be ephemeral (short-lived, stateless)

Page 54: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Containers vs. Virtual Machines

Page 55: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Containers vs. Virtual Machines

Page 56: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker run

• Run a command in a new container• Examples

٠ docker run ubuntu٠ docker run ubuntu:16.04٠ docker run -it ubuntu:16.04٠ docker run -it ubuntu:16.04 bash٠ docker run --name bob -it ubuntu:16.04 bash٠ docker run --name bob -it -v folder:/etc/folder -p 5000:80

ubuntu:16.04 bash

Page 57: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker ps

• List containers• Examples

٠ docker ps٠ docker ps -a

Page 58: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker logs

• Fetch the logs of a container• Examples:

٠ docker logs bob٠ docker logs -f bob٠ docker logs -f --tail 50 bob

Page 59: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker stop

• Stop one or more running containers• Examples:

٠ docker stop bob

Page 60: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker start

• Start one or more stopped containers• Examples:

٠ docker start bob

Page 61: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

docker rm

• Remove one or more containers• Examples

٠ docker rm bob٠ docker rm --force bob

Page 62: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Dockerfile

• A simple text file• Contains directives to execute for every layer

Page 63: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

DockerfileBase Image

Environment variables

Copy Code

Run command

Expose portDefault Command to execute

Default Arguments to command

Page 64: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Workshop

Page 65: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

workshop-docker-eth.beekeeper.io

Page 66: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time
Page 67: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Conclusion

Page 68: Slides: Workshop Resources · workshop-docker-eth.beekeeper.io. Conclusion. Next steps • You felt the pain of orchestration • Real services need a lot more of this • Next time

Next steps

• You felt the pain of orchestration• Real services need a lot more of this• Next time we can see how to get a “real” service

running• Explore tools like kubernetes