using kubernetes to lose your fear of using containers

46
Using kubernetes to lose your fear of using containers Jose Fuentes - [email protected] Toolchain Engineer @_jsfuentes

Upload: josfuecas

Post on 15-Apr-2017

152 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Using kubernetes to lose your fear of using containers

Using kubernetes to loseyour fear of using containers

Jose Fuentes - [email protected]

Toolchain Engineer

@_jsfuentes

Page 2: Using kubernetes to lose your fear of using containers

Kubernetes

- Run containers on a cluster

- Automatic deployment

- Scaling

- Designed for failure

Health checking

And other cool features

Manage containerized application

Load balancing

Rolling updates

Replication

Page 3: Using kubernetes to lose your fear of using containers

Kubernetes

- Run containers on a cluster

- Automatic deployment

- Scaling

- Designed for failure

Health checking

And other cool features

Manage containerized application

Load balancing

Rolling updates

Replication

Implies a contract with the applicationImplies a contract with the application

Page 4: Using kubernetes to lose your fear of using containers

It sounds interesting. Tell me more.

- Must-know concepts for understanding kubernetes

- How my app should be to take advantage of all the features

- And some other interesting things for operating apps with k8s

log management debugging

health checking failure recovery

monitoring metering

updating

Page 5: Using kubernetes to lose your fear of using containers

Must-know concepts

Page 6: Using kubernetes to lose your fear of using containers

Architecturekubectl

Master

Controller Manager

Scheduler

etcd

Kubernetes APIMinion

docker engine

pod

kube-proxykubelet

pod

Minion

docker engine

pod

kube-proxykubelet

pod

firewall/loadbalancer/

proxy

Top view

Page 7: Using kubernetes to lose your fear of using containers

Minion 1- Collection containers

- Unit of scheduling and replication

- Ephemeral, not durable

- They’re replaced, not resurrected

- Containers in the same pod share:- PIDs- Network- Hostname

Kubernetes Master

Pod Container A Container B

Minion 2

Minion 1

Pod PodContainer C Container D

ComponentsPods

Page 8: Using kubernetes to lose your fear of using containers

-

-

-

-

Services Types

You can’t communicate with pods directly

ComponentsServices

services allows to route traffic to a set of pods

http://railsapp:3000

Minion 1

kube-proxy

pod

Minion 2

kube-proxy

pod

serviceCloud ProviderLoadBalancer

Page 9: Using kubernetes to lose your fear of using containers

-

-

-

-

Services Types

You can’t communicate with pods directly

ComponentsServices

services allows to route traffic to a set of pods

Minion 1

kube-proxy

pod

Minion 2

kube-proxy

pod

http://minion1:3000 http://minion2:3000

Page 10: Using kubernetes to lose your fear of using containers

-

-

-

-

Services Types

You can’t communicate with pods directly

ComponentsServices

services allows to route traffic to a set of pods

Minion 1

kube-proxy

pod

Minion 2

kube-proxy

pod

serviceCloud ProviderLoadBalancer

http://<public IP>

Page 11: Using kubernetes to lose your fear of using containers

-

-

-

-

Services Types

You can’t communicate with pods directly

ComponentsServices

services allows to route traffic to a set of podsExternalName

external.service.com

internalname

Page 12: Using kubernetes to lose your fear of using containers

- Arbitrary metadata attached to any object

- key-value pairs

- Relevant attributes for users

- Allows to organize objects in the cluster

Labels

Selectors

- Identify a set of objects based on labels values

app: myapprole: webbranch: prod

app: myapprole: dbbranch: prod

app: myapprole: webbranch: dev

app: myapprole: dbbranch: dev

branch == prod branch == dev

Labels and selectors

Page 13: Using kubernetes to lose your fear of using containers

ExampleServiceLoadBalancer

Pod

:80

Containerweb

:3000

ServiceClusterIP

Pod

Containermongo

:27017

:27017

Page 14: Using kubernetes to lose your fear of using containers

ExampleServiceLoadBalancer

Pod

:80

Containerweb

:3000

ServiceClusterIP

Pod

Containermongo

:27017

:27017

Page 15: Using kubernetes to lose your fear of using containers

CLI and UI

Page 16: Using kubernetes to lose your fear of using containers

- Manage several clusters and contexts

- Get cluster info: nodes, pods, services, deployments

- Deploy/delete stuff

- Scale up/down (replicas)

- Interact with containers

- See logs

- Create tunnels (port forwarding)

Kubectl CLI http://kubernetes.io/docs/user-guide/docker-cli-to-kubectl/

Page 18: Using kubernetes to lose your fear of using containers

How an app should be to work well on k8s

Page 19: Using kubernetes to lose your fear of using containers

Let me tell you a secret...

Page 20: Using kubernetes to lose your fear of using containers

Kubernetes is not for everybody

Page 21: Using kubernetes to lose your fear of using containers

WishlistRestart should not be a pain

Your app is gonna be restarted often, so… stay prepared for that

- Start fast

- Don't cook assets at boot time

- Don't lose data on reboots

Page 22: Using kubernetes to lose your fear of using containers

WishlistData should be separated

Your app should be stateless.

The state should be stored apart.

uploaded files

sessions info

plugins

jobs

Oh man, that's easy. I mount a volume for my mariaDB and I am done.

It is not just the DB

Page 23: Using kubernetes to lose your fear of using containers

WishlistData schema compatible across versions

- That's not possible...- Well… at least do changes in a clever way

- Temporary maintain datastore compatible with two versions

- B/C changes

- Intermediate migrations

- Make logic to adapt API requests to the new format

Page 24: Using kubernetes to lose your fear of using containers

Example: Drupal blog

Database

Web server

Drupal php code v8.1 plugin

Web server

Drupal php code v8.2

Web server

Drupal php code v8.1 plugin

Page 25: Using kubernetes to lose your fear of using containers

Example: Drupal blog

Database

Web server

Drupal php code v8.1

Web server

Drupal php code v8.2

External volume

Web server

Drupal php code v8.1

plugin

Page 26: Using kubernetes to lose your fear of using containers

Underlying infrastructure

Page 27: Using kubernetes to lose your fear of using containers

A pet server

-You instantiated it time ago

-Then you manually installed thing you needed there

-You ssh it often because you like to manually check things there

-Eventually you go there and do some manual work to install

something

-Now you have an adorable pet that you really worry about

because it's something unique

Page 28: Using kubernetes to lose your fear of using containers

We want cattle servers

They are almost identicalEasily replaceable

DON'T SSH

Page 29: Using kubernetes to lose your fear of using containers

Manos a la obra!

Page 30: Using kubernetes to lose your fear of using containers

Our app

Containerweb

:3000

Containermongo

:27017

josefuentes/todolist docker build + docker push

bitnami/mongodb

Container images

Page 31: Using kubernetes to lose your fear of using containers

Our appDeployment info for kubernetes Service

LoadBalancer

Pod

:80

Containerweb

:3000

ServiceClusterIP

Pod

Containermongo

:27017

:27017

- Be aware of your app limitations

tier=web

tier=db

- Be tidy, use labels

- Be precise, set probes

replicas high availability configs

info stored in host

- If you know very well your app, limit the resources

Page 32: Using kubernetes to lose your fear of using containers

DebugGimme a shell!!!

List the pods

Use exec

kubectl get pods

kubectl exec -ti <mypod> -c <container> bash

Page 33: Using kubernetes to lose your fear of using containers

DebugSee logs

Use logskubectl logs <mypod> -c <container>

TIP: use -fkubectl logs -f <mypod> -c <container>

Page 34: Using kubernetes to lose your fear of using containers

DebugForward a port

Use logskubectl logs <mypod> -c <container>

TIP: use -fkubectl port-forward <mypod> [local_port:]remote_port

Page 35: Using kubernetes to lose your fear of using containers

Metering resources

Page 36: Using kubernetes to lose your fear of using containers

Failure recovery

Inside pods -> restart policies

In machines -> pods reallocation

Page 37: Using kubernetes to lose your fear of using containers

PodContainer 1 Container 2

RestartPolicy: Always

PodContainer 2Container 1

PodContainer 2Container 1

PodContainer 1 Container 2

RestartPolicy: Never

PodContainer 2Container 1

PodContainer 2Container 1

Failed

Failure recovery

Page 38: Using kubernetes to lose your fear of using containers

PodContainer 1 Container 2

PodContainer 2Container 1

PodContainer 2Container 1

PodContainer 2Container 1

Successful

RestartPolicy: OnFailure

Failure recovery

Page 39: Using kubernetes to lose your fear of using containers

PodContainer 1 Container 2

PodContainer 2Container 1

PodContainer 2Container 1

Failed

PodContainer 2Container 1

Successful

RestartPolicy: Never

Failure recovery

Page 40: Using kubernetes to lose your fear of using containers

Scalereplicas

Several instances of a pod

- Same configuration

- Normally on different machines

- LoadBalancing

- Better redundancy

Page 41: Using kubernetes to lose your fear of using containers

Scalereplicas

There are many ways of scaling your app.

It is important how do you design your pods

Pod

Apache Express

Pod

mongoDBServiceDB

Page 42: Using kubernetes to lose your fear of using containers

Scalereplicas

There are many ways of scaling your app.

It is important how do you design your pods

Pod

mongoDBServiceDB

Pod

Apache Express

Pod

Apache Express

Page 43: Using kubernetes to lose your fear of using containers

Scalereplicas

There are many ways of scaling your app.

It is important how do you design your pods

Pod

mongoDBServiceDB

Pod

Express

Pod

Apache

Pod

Apache

Page 44: Using kubernetes to lose your fear of using containers

Advanced log monitoring

http://kubernetes.io/docs/getting-started-guides/logging-elasticsearch/

Pods are ephemeral -> logs are not going to be there forever

Solution -> log live ingestion

Pod

Page 45: Using kubernetes to lose your fear of using containers

Podversion=1

Podversion=1

Podversion=1

Podversion=1

ServiceLoadBalancer

Podversion=2

Podversion=2

$ kubectl set image deploy <your deploy> <container>=<image>

Rolling out new features

Page 46: Using kubernetes to lose your fear of using containers

Thank You