KubeCon EU 2016: Your App Is Alive

46
Your App Is Alive Michelle Noorali Developer at Deis @michellenoorali

Transcript of KubeCon EU 2016: Your App Is Alive

Page 1: KubeCon EU 2016: Your App Is Alive

Your App Is AliveMichelle Noorali

Developer at Deis@michellenoorali

Page 2: KubeCon EU 2016: Your App Is Alive

Helm• Kubernetes Package Manager

• Packages = “Charts”

• “Homebrew” for Kubernetes

• Great way to find, share, and use software built for Kubernetes

• Community focused

• www.helm.sh

Page 3: KubeCon EU 2016: Your App Is Alive

Helm ChartsKubernetes manifests + metadata

Page 4: KubeCon EU 2016: Your App Is Alive

Try it outgithub.com/helm/charts

Page 5: KubeCon EU 2016: Your App Is Alive

Health Checks

Page 6: KubeCon EU 2016: Your App Is Alive

What?

Page 7: KubeCon EU 2016: Your App Is Alive

a way to monitor your app’s health

A Health Check is

Page 8: KubeCon EU 2016: Your App Is Alive

Is your app…responsive?

Page 9: KubeCon EU 2016: Your App Is Alive

Is your app…Performant?

Page 10: KubeCon EU 2016: Your App Is Alive

Is your app…Stable?

Page 11: KubeCon EU 2016: Your App Is Alive

What does it look like?

Page 12: KubeCon EU 2016: Your App Is Alive

• /healthcheck or /healthz endpoint

• checked by external system at intervals

• On success, do nothing

• On failure, notify and heal

Health checks continued …

Page 13: KubeCon EU 2016: Your App Is Alive

In Kubernetes Land…

• Health checks are built in! • But first…

Page 14: KubeCon EU 2016: Your App Is Alive

Introducing Puffy• … a simple go web server

Page 15: KubeCon EU 2016: Your App Is Alive

Pre-requisites

• Running Kubernetes cluster on GCE [Google Compute Engine]

• Docker Image for app stored on DockerHub

• DockerHub = place to store images

• Can also use Quay.io or GCR [Google Container Registry]

Page 16: KubeCon EU 2016: Your App Is Alive

Puffy Repo

Page 17: KubeCon EU 2016: Your App Is Alive

Dockerfile

Page 18: KubeCon EU 2016: Your App Is Alive

Makefile

Page 19: KubeCon EU 2016: Your App Is Alive

Manifest file

Page 20: KubeCon EU 2016: Your App Is Alive

Life of Puffy: It’s Alive• Create a pod definition in manifest

• Create resource in kubernetes from manifest with $ kubectl create -f puffy-pod.yaml

• Watch it come to life with $ kubectl get pods -w

• Talk to a route

• curl pod_ip:port/index on a node

• https://asciinema.org/a/7okfmusa0c368obqxba8t9my4

Page 21: KubeCon EU 2016: Your App Is Alive

Let’s make sure puffy is ok.

Here comes the health check part…

Page 22: KubeCon EU 2016: Your App Is Alive

Two Probes walk into a coffeeshop…

• Readiness Probe

• Liveness Probe

Page 23: KubeCon EU 2016: Your App Is Alive

Wait. What is this probe thing?

• a probe = a diagnostic periodically performed on a container

• Three ways to perform a diagnostic:

• Execute a command in a container

• Successful if exit status code 0

• Perform tcp check on a container’s IP address on a specific port

• Successful if the port is open

• Perform an HTTP Get against the container’s IP address on a specific port

• Successful if response has status code >= 200 and <400

Page 24: KubeCon EU 2016: Your App Is Alive

Back to the probes…• Readiness Probe

• Is my app ready to serve traffic?

• On failure, it stops serving requests

• Liveness Probe

• Is my app in a good state?

• On failure, it restarts the pod

Page 25: KubeCon EU 2016: Your App Is Alive

Define a Liveness Probe in the Pod Manifest

Page 26: KubeCon EU 2016: Your App Is Alive

Apply the Changes in the Pod Manifest to the Cluster

$ kubectl delete -f puffy-pod.yaml

~ edit puffy-pod.yaml ~

$ kubectl create -f pod-puffy.yaml

Page 27: KubeCon EU 2016: Your App Is Alive

You’ll see failure

Page 28: KubeCon EU 2016: Your App Is Alive

Oops• Forgot to add the /healthz endpoint

• kubectl delete -f puffy-pod.yaml

Page 29: KubeCon EU 2016: Your App Is Alive

Add /healthz

• Define /healthz in app (common convention)

• Re-build/re-tag image

• Push image to registry

• Edit image declaration in manifest

Page 30: KubeCon EU 2016: Your App Is Alive

Bring Puffy Back!

$ kubectl create -f puffy-pod.yaml or $ helm install puffy

$ kubectl get pods

$ kubectl describe pod puffy

On node, curl ip:port/healthz

Page 31: KubeCon EU 2016: Your App Is Alive

Let’s add some complexity.

Page 32: KubeCon EU 2016: Your App Is Alive
Page 33: KubeCon EU 2016: Your App Is Alive

Puffy on /play

Page 34: KubeCon EU 2016: Your App Is Alive

Puffy + Spotify API

Page 35: KubeCon EU 2016: Your App Is Alive

ReadinessProbe Definition

Page 36: KubeCon EU 2016: Your App Is Alive

/ready

Page 37: KubeCon EU 2016: Your App Is Alive

Now we need a redis pod to hang out with

Page 38: KubeCon EU 2016: Your App Is Alive

Find a redis chart … to borrow some manifests

Page 39: KubeCon EU 2016: Your App Is Alive
Page 40: KubeCon EU 2016: Your App Is Alive

and create our own chart

Page 41: KubeCon EU 2016: Your App Is Alive

www.github.com/michelleN/helm-charts/many-directions

Page 42: KubeCon EU 2016: Your App Is Alive

$ helm repo add michelle https://github.com/michelleN/many-directions$ helm repo list$ helm search many-directions$ helm install many-directions

Page 43: KubeCon EU 2016: Your App Is Alive

Things to watch out for

• Try to leave health checks as simple as possible

• Don’t get too aggressive

• Use the right probe for your situation

Page 44: KubeCon EU 2016: Your App Is Alive

Summary• Automate monitoring apps with health checks

• Use Kubernetes’s built in health check features

• readinessProbe

• Is your app ready to serve traffic?

• livenessProbe

• Is your app in a good state?

Page 45: KubeCon EU 2016: Your App Is Alive

Deployment Manager

+

Coming together to bring you a simple and powerful way to deploy and manage Kubernetes

Charts and is going to CNCF along with the rest of Kubernetes

Page 46: KubeCon EU 2016: Your App Is Alive

That’s it folks. Thank you.Puffy: www.github.com/michelleN/puffy Many-directions: www.github.com/michelleN/many-directions My charts: www.github.com/michelleN/charts Helm: www.helm.sh Helm charts: www.github.com/helm/charts

Look for www.github.com/kubernetes/helm

& www.github.com/kubernetes/charts

@michellenoorali