Update init containers documentation with 1.6 syntax for YAML files (#3572)

* Syntax for Kubernetes version 1.6

Included 1.6 syntax change for declaration of init containers.

* Reorder services.yaml & add 1.5 syntax still works

* Corrected YAML headings & add syntax explanation
pull/3580/head
Jun Xiang Tee 2017-04-28 15:59:09 -07:00 committed by Andrew Chen
parent 039b1b395c
commit fd3dcaaab6
1 changed files with 52 additions and 4 deletions

View File

@ -98,7 +98,7 @@ and the [Production Pods guide](/docs/user-guide/production-pods.md#handling-ini
### Init Containers in use
The following yaml file outlines a simple Pod which has two Init Containers.
The following yaml file for Kubernetes 1.5 outlines a simple Pod which has two Init Containers.
The first waits for `myservice` and the second waits for `mydb`. Once both
containers complete the Pod will begin.
@ -129,6 +129,55 @@ spec:
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
```
There is a slight change of syntax in Kubernetes 1.6. We move declaration of the init containers to `spec`:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox
command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
- name: init-mydb
image: busybox
command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']
```
1.5 syntax still works on 1.6, but we recommend using 1.6 syntax. In Kubernetes 1.6, init containers were made a field in the API. The beta annotation is still respected but will be deprecated in future releases.
Yaml file below outlines the `mydb` and `myservice` services:
```
kind: Service
apiVersion: v1
metadata:
name: myservice
spec:
ports:
- protocol: TCP
port: 80
targetPort: 9376
---
kind: Service
apiVersion: v1
metadata:
name: mydb
spec:
ports:
- protocol: TCP
port: 80
targetPort: 9377
```
This Pod can be started and debugged with the following commands:
```
@ -137,8 +186,7 @@ pod "myapp-pod" created
$ kubectl get -f myapp.yaml
NAME READY STATUS RESTARTS AGE
myapp-pod 0/1 Init:0/2 0 6m
$ kubectl describe -f myapp.yaml
i11:32 $ kubectl describe -f examples/init-container.yaml
$ kubectl describe -f myapp.yaml
Name: myapp-pod
Namespace: default
[...]
@ -173,7 +221,7 @@ $ kubectl logs myapp-pod -c init-myservice # Inspect the first init container
$ kubectl logs myapp-pod -c init-mydd # Inspect the second init container
```
Once we start the `mydb` and `myservice` Services we can see the Init Containers
Once we start the `mydb` and `myservice` services we can see the Init Containers
complete and the `myapp-pod` is created:
```