From 205a3007a810e0fbeb801cdb06f0bc23c208a595 Mon Sep 17 00:00:00 2001 From: steveperry-53 Date: Tue, 3 Jan 2017 10:14:46 -0800 Subject: [PATCH] Write new task: Configuring Pod Initialization. --- _data/tasks.yml | 1 + .../configure-pod-initialization.md | 91 +++++++++++++++++++ .../init-containers.yaml | 32 +++++++ 3 files changed, 124 insertions(+) create mode 100644 docs/tasks/configure-pod-container/configure-pod-initialization.md create mode 100644 docs/tasks/configure-pod-container/init-containers.yaml diff --git a/_data/tasks.yml b/_data/tasks.yml index 9f7f832aa9..9605e925b0 100644 --- a/_data/tasks.yml +++ b/_data/tasks.yml @@ -13,6 +13,7 @@ toc: - docs/tasks/configure-pod-container/pull-image-private-registry.md - docs/tasks/configure-pod-container/configure-liveness-readiness-probes.md - docs/tasks/configure-pod-container/communicate-containers-same-pod.md + - docs/tasks/configure-pod-container/configure-pod-initialization.md - title: Accessing Applications in a Cluster section: diff --git a/docs/tasks/configure-pod-container/configure-pod-initialization.md b/docs/tasks/configure-pod-container/configure-pod-initialization.md new file mode 100644 index 0000000000..add65b09ee --- /dev/null +++ b/docs/tasks/configure-pod-container/configure-pod-initialization.md @@ -0,0 +1,91 @@ +--- +title: Configuring Pod Initialization +--- + +{% capture overview %} +This page shows how to use an init Container to initialize a Pod before the +application Container runs. + +{% endcapture %} + +{% capture prerequisites %} + +{% include task-tutorial-prereqs.md %} + +{% endcapture %} + +{% capture steps %} + +### Creating a Pod that has an init Container + +In this exercise you create a Pod that has one application Container and one +init Container. The init Container runs to completion before the application +container starts. + +Here is the configuration file for the Pod: + +{% include code.html language="yaml" file="init-containers.yaml" ghlink="/docs/tasks/configure-pod-container/init-containers.yaml" %} + +In the configuration file, you can see that the Pod has a Volume that the init +Container and the application Container share. Notice that the init Container +is a beta feature and is specified as an annotation. + +The init Container mounts the +shared Volume at `/work-dir`, and the application Container mounts the shared +Volume at `/usr/share/nginx/html`. The init Container runs the following command +and then terminates: + + wget -O /work-dir/index.html http://kubernetes.io + +Notice that the init Container writes the `index.html` file in the root directory +of the nginx server. + +Create the Pod: + + kubectl create -f http://k8s.io/docs/tasks/configure-pod-container/init-containers.yaml + +Verify that the nginx Container is running: + + kubectl get pod init-demo + +The output shows that the nginx Container is running: + + NAME READY STATUS RESTARTS AGE + nginx 1/1 Running 0 43m + +Get a shell into nginx the Container running in the init-demo Pod: + + kubectl exec -it init-demo -- /bin/bash + +In your shell, send a GET request to the nginx server: + + root@nginx:~# apt-get update + root@nginx:~# apt-get install curl + root@nginx:~# curl localhost + +The output shows that nginx is serving the web page that was written by the init container: + + + + + + ... + "url": "http://kubernetes.io/"} + + + ... +

Kubernetes is open source giving you the freedom to take advantage ...

+ ... + +{% endcapture %} + +{% capture whatsnext %} + +* Learn more about +[communicating between Containers running in the same Pod](/docs/tasks/configure-pod-container/communicate-containers-same-pod/). +* Learn more about [init Containers](/docs/user-guide/pods/init-container/). +* Learn more about [Volumes](/docs/user-guide/volumes/). + +{% endcapture %} + +{% include templates/task.md %} diff --git a/docs/tasks/configure-pod-container/init-containers.yaml b/docs/tasks/configure-pod-container/init-containers.yaml new file mode 100644 index 0000000000..80e135b459 --- /dev/null +++ b/docs/tasks/configure-pod-container/init-containers.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Pod +metadata: + name: init-demo + annotations: + pod.beta.kubernetes.io/init-containers: '[ + { + "name": "install", + "image": "busybox", + "command": ["wget", "-O", "/work-dir/index.html", "http://kubernetes.io"], + "volumeMounts": [ + { + "name": "workdir", + "mountPath": "/work-dir" + } + ] + } + ]' +spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 + volumeMounts: + - name: workdir + mountPath: /usr/share/nginx/html + dnsPolicy: Default + volumes: + - name: workdir + emptyDir: {} +