Skip to content

Latest commit

 

History

History
122 lines (105 loc) · 2.42 KB

uebung-liveness.md

File metadata and controls

122 lines (105 loc) · 2.42 KB

Übung Liveness

Übung 1: Liveness (command)

What does it do ? 
 
* At the beginning pod is ready (first 30 seconds)
* Check will be done after 5 seconds of pod being startet
* Check will be done periodically every 5 minutes and will check
  * for /tmp/healthy
  * if file is there will return: 0 
  * if file is not there will return: 1 
* After 30 seconds container will be killed
* After 35 seconds container will be restarted
# cd
# mkdir -p manifests/probes
# cd manifests/probes 
# vi 01-pod-liveness-command.yml 

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
# apply and test 
kubectl apply -f 01-pod-liveness-command.yml 
kubectl describe -l test=liveness pods 
sleep 30
kubectl describe -l test=liveness pods 
sleep 5 
kubectl describe -l test=liveness pods 
# cleanup
kubectl delete -f 01-pod-liveness-command.yml
 

Übung 2: Liveness Probe (HTTP)

# Step 0: Understanding Prerequisite:
This is how this image works:
# after 10 seconds it returns code 500 
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
    duration := time.Now().Sub(started)
    if duration.Seconds() > 10 {
        w.WriteHeader(500)
        w.Write([]byte(fmt.Sprintf("error: %v", duration.Seconds())))
    } else {
        w.WriteHeader(200)
        w.Write([]byte("ok"))
    }
})
# Step 1: Pod  - manifest 
# vi 02-pod-liveness-http.yml
# status-code >=200 and < 400 o.k. 
# else failure 
apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3
# Step 2: apply and test
kubectl apply -f 02-pod-liveness-http.yml
# after 10 seconds port should have been started 
sleep 10 
kubectl describe pod liveness-http

Reference: