From 2dcecf1f6574a178e343d09a595841faf79f26fc Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Wed, 13 May 2015 13:03:28 -0700 Subject: [PATCH] update example/liveness to v1beta3; update the exec-liveness.yaml to reflect PR#8011 add a README --- examples/examples_test.go | 4 ++ examples/liveness/README.md | 76 ++++++++++++++++++++ examples/liveness/exec-liveness.yaml | 41 ++++++----- examples/liveness/http-liveness.yaml | 35 +++++---- examples/liveness/v1beta3/exec-liveness.yaml | 29 -------- examples/liveness/v1beta3/http-liveness.yaml | 26 ------- 6 files changed, 117 insertions(+), 94 deletions(-) create mode 100644 examples/liveness/README.md delete mode 100644 examples/liveness/v1beta3/exec-liveness.yaml delete mode 100644 examples/liveness/v1beta3/http-liveness.yaml diff --git a/examples/examples_test.go b/examples/examples_test.go index b0b3b4ece03..454f33fb0bf 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -164,6 +164,10 @@ func TestExampleObjectSchemas(t *testing.T) { "../examples/glusterfs/v1beta3": { "glusterfs": &api.Pod{}, }, + "../examples/liveness": { + "exec-liveness": &api.Pod{}, + "http-liveness": &api.Pod{}, + }, "../examples": { "pod": &api.Pod{}, "replication": &api.ReplicationController{}, diff --git a/examples/liveness/README.md b/examples/liveness/README.md new file mode 100644 index 00000000000..5092cd3efde --- /dev/null +++ b/examples/liveness/README.md @@ -0,0 +1,76 @@ +## Overview +This example shows two types of pod health checks: HTTP checks and container execution checks. + +The [exec-liveness.yaml](./exec-liveness.yaml) demonstrates the container execution check. +``` + livenessProbe: + exec: + command: + - cat + - /tmp/health + initialDelaySeconds: 15 + timeoutSeconds: 1 +``` +Kubelet executes the command cat /tmp/health in the container and reports failure if the command returns a non-zero exit code. + +Note that the container removes the /tmp/health file after 10 seconds, +``` +echo ok > /tmp/health; sleep 10; rm -rf /tmp/health; sleep 600 +``` +so when Kubelet executes the health check 15 seconds (defined by initialDelaySeconds) after the container started, the check would fail. + + +The [http-liveness.yaml](./http-liveness.yaml) demonstrates the HTTP check. +``` + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 15 + timeoutSeconds: 1 +``` +The Kubelet sends a HTTP request to the specified path and port to perform the health check. If you take a look at image/server.go, you will see the server starts to respond with an error code 500 after 10 seconds, so the check fails. + +This [guide](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/examples/walkthrough/k8s201.md#health-checking) has more information on health checks. + +## Get your hands dirty +To show the health check is actually working, first create the pods: +``` +# cluster/kubectl.sh create -f exec-liveness.yaml +# cluster/kbuectl.sh create -f http-liveness.yaml +``` + +Check the status of the pods once they are created: +``` +# cluster/kubectl.sh get pods +POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE +liveness-exec 10.244.3.7 kubernetes-minion-f08h/130.211.122.180 test=liveness Running 3 seconds + liveness gcr.io/google_containers/busybox Running 2 seconds +liveness-http 10.244.0.8 kubernetes-minion-0bks/104.197.10.10 test=liveness Running 3 seconds + liveness gcr.io/google_containers/liveness Running 2 seconds +``` + +Check the status half a minute later, you will see the termination messages: +``` +# cluster/kubectl.sh get pods +POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE +liveness-exec 10.244.3.7 kubernetes-minion-f08h/130.211.122.180 test=liveness Running 34 seconds + liveness gcr.io/google_containers/busybox Running 3 seconds last termination: exit code 137 +liveness-http 10.244.0.8 kubernetes-minion-0bks/104.197.10.10 test=liveness Running 34 seconds + liveness gcr.io/google_containers/liveness Running 13 seconds last termination: exit code 2 +``` +The termination messages indicate that the liveness probes have failed, and the containers have been killed and recreated. + +You can also see the container restart count being incremented by running `kubectl describe`. +``` +# cluster/kubectl.sh describe pods liveness-exec | grep "Restart Count" +Restart Count: 8 +``` + +You would also see the killing and creating events at the bottom of the *kubectl describe* output: +``` + Thu, 14 May 2015 15:23:25 -0700 Thu, 14 May 2015 15:23:25 -0700 1 {kubelet kubernetes-minion-0uzf} spec.containers{liveness} killing Killing 88c8b717d8b0940d52743c086b43c3fad0d725a36300b9b5f0ad3a1c8cef2d3e + Thu, 14 May 2015 15:23:25 -0700 Thu, 14 May 2015 15:23:25 -0700 1 {kubelet kubernetes-minion-0uzf} spec.containers{liveness} created Created with docker id b254a9810073f9ee9075bb38ac29a4b063647176ad9eabd9184078ca98a60062 + Thu, 14 May 2015 15:23:25 -0700 Thu, 14 May 2015 15:23:25 -0700 1 {kubelet kubernetes-minion-0uzf} spec.containers{liveness} started Started with docker id b254a9810073f9ee9075bb38ac29a4b063647176ad9eabd9184078ca98a60062 + ... +``` diff --git a/examples/liveness/exec-liveness.yaml b/examples/liveness/exec-liveness.yaml index 4e1ba960c64..b72dac0f595 100644 --- a/examples/liveness/exec-liveness.yaml +++ b/examples/liveness/exec-liveness.yaml @@ -1,22 +1,21 @@ -apiVersion: v1beta1 -desiredState: - manifest: - containers: - - image: gcr.io/google_containers/busybox - name: liveness - livenessProbe: - exec: - command: - - "cat" - - "/tmp/health" - initialDelaySeconds: 15 - command: - - "/bin/sh" - - "-c" - - "echo ok > /tmp/health; sleep 10; echo fail > /tmp/health; sleep 600" - id: liveness-exec - version: v1beta1 -id: liveness-exec +apiVersion: v1beta3 kind: Pod -labels: - test: liveness +metadata: + labels: + test: liveness + name: liveness-exec +spec: + containers: + - args: + - /bin/sh + - -c + - echo ok > /tmp/health; sleep 10; rm -rf /tmp/health; sleep 600 + image: gcr.io/google_containers/busybox + livenessProbe: + exec: + command: + - cat + - /tmp/health + initialDelaySeconds: 15 + timeoutSeconds: 1 + name: liveness diff --git a/examples/liveness/http-liveness.yaml b/examples/liveness/http-liveness.yaml index 8f81dd5c7e7..36d3d70caf0 100644 --- a/examples/liveness/http-liveness.yaml +++ b/examples/liveness/http-liveness.yaml @@ -1,19 +1,18 @@ -apiVersion: v1beta1 -desiredState: - manifest: - containers: - - image: gcr.io/google_containers/liveness - name: liveness - livenessProbe: - httpGet: - path: "/healthz" - port: 8080 - initialDelaySeconds: 15 - command: - - /server - id: liveness-http - version: v1beta1 -id: liveness-http +apiVersion: v1beta3 kind: Pod -labels: - test: liveness +metadata: + labels: + test: liveness + name: liveness-http +spec: + containers: + - args: + - /server + image: gcr.io/google_containers/liveness + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 15 + timeoutSeconds: 1 + name: liveness diff --git a/examples/liveness/v1beta3/exec-liveness.yaml b/examples/liveness/v1beta3/exec-liveness.yaml deleted file mode 100644 index 068c7d8c351..00000000000 --- a/examples/liveness/v1beta3/exec-liveness.yaml +++ /dev/null @@ -1,29 +0,0 @@ -apiVersion: v1beta3 -kind: ReplicationController -metadata: - labels: - test: liveness - name: liveness-exec -spec: - replicas: 1 - selector: - test: liveness - template: - metadata: - labels: - test: liveness - spec: - containers: - - command: - - "/bin/sh" - - "-c" - - "echo ok > /tmp/health; sleep 10; echo fail > /tmp/health; sleep 600" - image: gcr.io/google_containers/busybox - livenessProbe: - exec: - command: - - "cat" - - "/tmp/health" - initialDelaySeconds: 15 - name: liveness - diff --git a/examples/liveness/v1beta3/http-liveness.yaml b/examples/liveness/v1beta3/http-liveness.yaml deleted file mode 100644 index 36328fd908b..00000000000 --- a/examples/liveness/v1beta3/http-liveness.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: v1beta3 -kind: ReplicationController -metadata: - labels: - test: liveness - name: liveness-http -spec: - replicas: 1 - selector: - test: liveness - template: - metadata: - labels: - test: liveness - spec: - containers: - - command: - - "/server" - image: gcr.io/google_containers/liveness - livenessProbe: - httpGet: - path: "/healthz" - port: 8080 - initialDelaySeconds: 15 - name: liveness -