How to install and use Kubernetes

43
How to install and use Kubernetes Luke Marsden, Developer Experience @lmarsden

Transcript of How to install and use Kubernetes

Page 1: How to install and use Kubernetes

How to install and use Kubernetes

Luke Marsden, Developer Experience@lmarsden

Page 2: How to install and use Kubernetes

What does Weave do?

Weave helps devops iterate faster with: • observability &

monitoring • continuous delivery • container networks

& firewalls

Kubernetes is our #1 platform

Page 3: How to install and use Kubernetes

Agenda1. Concepts 2. Containers, Pods, Deployments, Services 3. Installing Kubernetes 4. Demos of Pods, Deployments, Services 5. Microservices sample app 6. What’s next?

Page 4: How to install and use Kubernetes

Kubernetes: all you need to know

Pods

containers

Services

Deployments

Page 5: How to install and use Kubernetes

Concepts

Computer

Page 6: How to install and use Kubernetes

Concepts

Node

Page 7: How to install and use Kubernetes

Concepts

nginx Containerimage: nginx:1.7.9

Node

Page 8: How to install and use Kubernetes

web

Concepts

nginx ContainerPod

logger

Node

Page 9: How to install and use Kubernetes

web

Concepts

nginx ContainerPod

logger

IP addr

Node

Page 10: How to install and use Kubernetes

web

Concepts

Pod nginx

apiVersion: v1 kind: Pod metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

Node

Page 11: How to install and use Kubernetes

Recap: all you need to know

Pods containers

Container Image

Docker container image, contains your application code in an isolated environment.

Pod A set of containers, sharing network namespace and local volumes, co-scheduled on one machine. Mortal. Has pod IP. Has labels.

Page 12: How to install and use Kubernetes

Motivation for Deployments

Node 1

Podweb

nginx

Node 2

Page 13: How to install and use Kubernetes

Motivation for Deployments

Podweb

nginx

Node 1 Node 2

Page 14: How to install and use Kubernetes

Motivation for Deployments

Podweb

nginx

Node 1 Node 2

Page 15: How to install and use Kubernetes

Deployment

web

nginx

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

Node 1

Page 16: How to install and use Kubernetes

Deployment

web

nginx

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

Node 1

Page 17: How to install and use Kubernetes

Deployment

web

nginx

Node 1 Node 2

Page 18: How to install and use Kubernetes

Deployment

web

nginx

Node 1 Node 2

Page 19: How to install and use Kubernetes

Deployment

web

nginx

Node 1 Node 2

Page 20: How to install and use Kubernetes

Deployment

web

nginx

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

Node 1

Page 21: How to install and use Kubernetes

Deployment

web

nginx

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

Node 1

Page 22: How to install and use Kubernetes

Deployment

web

nginx

web

nginx

Node 1 Node 2

Page 23: How to install and use Kubernetes

Recap: all you need to know

Pods containers

Deployments

Container Image

Docker container image, contains your application code in an isolated environment.

Pod A set of containers, sharing network namespace and local volumes, co-scheduled on one machine. Mortal. Has pod IP. Has labels.

Deployment Specify how many replicas of a pod should run in a cluster. Then ensures that many are running across the cluster.

Page 24: How to install and use Kubernetes

Service discovery• Kubernetes provides DNS for service

discovery

Page 25: How to install and use Kubernetes

Service discovery• Kubernetes provides DNS for service

discovery

WAIT! You said “service”.

What is a service?

Page 26: How to install and use Kubernetes

Services: ClusterIP (internal things)

Computer 1

web

ruby

Computer 2

10.0.0.1db

pgsql

10.0.0.2

service VIP10.1.0.1DNS lookup “db”

returns A 10.1.0.1

Page 27: How to install and use Kubernetes

Services: ClusterIP (internal things)

Computer 1

web

ruby

Computer 2

10.0.0.1db

pgsql

10.0.0.2

service VIP10.1.0.1

Page 28: How to install and use Kubernetes

Services: NodePort (external)

Computer 1

web

nginx

web

nginx

10.0.0.1 10.0.0.2

81.23.64.18 81.23.64.19

requests requests

Computer 2

Page 29: How to install and use Kubernetes

Computer 1

web

nginx

web

nginx

10.0.0.1 10.0.0.2

81.23.64.18 81.23.64.19

requests requests

Computer 2

Services: NodePort (external)NodePort 30001service VIP10.1.0.1

NodePort 30001service VIP10.1.0.1

Page 30: How to install and use Kubernetes

Computer 1

web

nginx

web

nginx

10.0.0.1 10.0.0.2

81.23.64.18 81.23.64.19

requests requests

Computer 2

Services: NodePort (external)NodePort 30001service VIP10.1.0.1

NodePort 30001service VIP10.1.0.1

Page 31: How to install and use Kubernetes

kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

kind: Service metadata: name: frontend spec: type: NodePort selector: app: nginx ports: - port: 80 targetPort: 80 nodePort: 30002

Using selectorsHow do services connect to deployments?

matches

Page 32: How to install and use Kubernetes

kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9

kind: Service metadata: name: frontend spec: type: NodePort selector: app: nginx ports: - port: 80 targetPort: 80 nodePort: 30002

How do you expose services to outside?Using NodePort

Page 33: How to install and use Kubernetes

Recap: all you need to know

Pods containers

ServicesDeployments

Container Image

Docker container image, contains your application code in an isolated environment.

Pod A set of containers, sharing network namespace and local volumes, co-scheduled on one machine. Mortal. Has pod IP. Has labels.

Deployment Specify how many replicas of a pod should run in a cluster. Then ensures that many are running across the cluster. Has labels.

Service Names things in DNS. Gets virtual IP. Two types: ClusterIP for internal services, NodePort for publishing to outside. Routes based on labels.

Page 34: How to install and use Kubernetes

Architecture of Kubernetes itself

Node 1 Node 2

Master

Page 35: How to install and use Kubernetes

API server

Architecture of Kubernetes itself

Node 1 Node 2

Master

API server etcd

kubeadm init

Page 36: How to install and use Kubernetes

API server

Architecture of Kubernetes itself

Node 1 Node 2

Master

API server etcd

kubeadm init

kubeadm join

kubelet

Page 37: How to install and use Kubernetes

API server

Architecture of Kubernetes itself

Node 1 Node 2

Master

API server etcd

kubeadm init

kubeadm join kubeadm join

kubelet kubelet

Page 38: How to install and use Kubernetes

API server

Architecture of Kubernetes itself

Node 1 Node 2

Master

API server etcd

kubeadm init

kubeadm join kubeadm join

kubelet kubelet

kubectl apply

Page 39: How to install and use Kubernetes

API server

Architecture of Kubernetes itself

Node 1 Node 2

Master

containersServices

containers

API server etcd

kubeadm init

kubeadm join kubeadm join

kubectl apply

kubelet kubelet

Page 40: How to install and use Kubernetes

Training!

Page 41: How to install and use Kubernetes

Join the Weave user group!

meetup.com/pro/Weave/ weave.works/help

Page 42: How to install and use Kubernetes

What’s next?

• Continuous delivery: hooking up my CI/CD pipeline to Kubernetes

• How do I monitor this stuff? • Network policy for security

Come to our Weave Cloud training to find out!

Page 43: How to install and use Kubernetes

Thanks! Questions?

We are hiring!DX in San Francisco

Engineers in London & SF

weave.works/weave-company/hiring