website/docs/concepts/workloads/pods/init-containers.md

325 lines
13 KiB
Markdown
Raw Normal View History

---
approvers:
- erictune
title: Init Containers
---
{% capture overview %}
This page provides an overview of Init Containers, which are specialized
Containers that run before app Containers and can contain utilities or setup
scripts not present in an app image.
{% endcapture %}
{:toc}
2017-05-06 03:50:17 +00:00
This feature has exited beta in 1.6. Init Containers can be specified in the PodSpec
alongside the app `containers` array. The beta annotation value will still be respected
and overrides the PodSpec field value.
{% capture body %}
## Understanding Init Containers
A [Pod](/docs/concepts/abstractions/pod/) can have multiple Containers running
apps within it, but it can also have one or more Init Containers, which are run
before the app Containers are started.
Init Containers are exactly like regular Containers, except:
* They always run to completion.
* Each one must complete successfully before the next one is started.
If an Init Container fails for a Pod, Kubernetes restarts the Pod repeatedly until the Init
Container succeeds. However, if the Pod has a `restartPolicy` of Never, it is not restarted.
To specify a Container as an Init Container, add the `initContainers` field on the PodSpec as a JSON array of objects of type [v1.Container](/docs/api-reference/{{page.version}}/#container-v1-core) alongside the app `containers` array.
Move init containers to stable in v1.6 (#1939) * Delete the parameter "--google-json-key string" Delete the parameter "--google-json-key string" * Fix apimachinery vendored dependencies in examples_test. * package apt-transport-https should be installed Ubuntu default install not include apt-transport-https. so if you want to download package from https repo, you need install apt-transport-https package first * doc-walkthrough-content modify * limitrange-update I think it's redundant that the second to ,in order to do sth and do sth!thanks! * fix command kubectl get svc,pod output fix command kubectl get svc,pod output * Fix typo: federation-controller-mananger => federation-controller-manager * Fix typo: federation-controller-mananger => federation-controller-manager * Clarify minimum version of kubernetes supporting PSP authz * Provide correct location for KUBE_ETCD_SERVERS Provide correct location for KUBE_ETCD_SERVERS configuration key. It was previously listed as being in /etc/kubernetes/config but is actually in /etc/kubernetes/apiserver. Related: https://github.com/kubernetes/kubernetes.github.io/issues/1600 * Move Compute Resources topic to Concepts. (#2410) * Delete the parameter "--google-json-key string" “# kube-scheduler -help”can not find --google-json-key option # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * Add diagnose tips when you face problem. * Update grammar for kubeadm.md, thanks @chenopis * Merge two pieces to one words * add http proxy infomation in kubeadm * Update landing pages for Tasks and Tutorials. (#2634) * Update static-pods.md It works. Please review it again. * Move Guide Topic: Multi-container pods. (#2642) * fix link to go to pod-lifecycle page * fix the command output fix the command output * mirantis_logo.png ,/images/community_logos/mirantis_logo.png updated per Mirantis request * kubeadm reference -- / set up/manage mean set up or manage ? it's better use or? * Prototype for deprecating User Guide topic. * missing word The return of the OCD. * Move Guide topic: Using Environment Variables. (#2645) * fix typo (#2656) fix typo * Move Guide topic: Using Port Forwarding. (#2661) * Move Guide topic: Bootstrapping Pet Sets. (#2662) * Move Guide topic: Bootstrapping Pet Sets. * Add TOC entry. * Move Guide topic: Connect with Proxies. (#2663) * Move Guide topic: Connect with Proxies. * Fix link. * add DefaultTolerationSeconds admission controller * getting-started-guides: add CoreOS Tectonic * Correct the certificate name * Update index.md * Update installation.md * Update validation.md * Update backups.md * Update backups.md * Spell fixes * Using it vs Juju Kubernetes * Q1 update to k8s tech and service partner list New partners registered to K8s Partner Ecosystem sign-up form. Logo updates companion to this edit still WIP * Logo file updates for new registrants Logos for new registrants * The attribute [allowfullscree] must have a value Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Remove newline before passing to base64 * Use single quote to avoid string interpolation, update output * Update command as files contain no newline * Remove all dead links, use just filename As user can guess that it is file copied from the shown content * Fix link to dev guide. * Add --leader-elect=false Second scheduler could not start without disabling leader-elect. * cluster-components-could be running could be doing sth * update cluster-components.md In theory,Master components can be run.... * update cluster-components--add a space add a space after the comma: "In theory, Master components..." * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * Revert "Highlighted command --kubectl describe" This reverts commit a70d0a3e3537c3f91b197b23f949e1e506c951d1. * Add example show how to configure proxy for kube * Revision as the suggestion describe * move ha-master-gce.png to images/docs Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * use relative path for ha-master-gce image Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * The attribute [calendarWrapper] must be unique Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * add required images in kubeadm init step * Add links to Docker/rtk in cluster-intro.html * s/acomplish/accomplish/ * Modify the link URL of [kubelet eviction design doc] [kubelet eviction design doc] should be linked to kubernetes.github.io instead of community/design-proposal. * fix CronJob object name fix CronJob object name * remove redundant a Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * kubeadm reference--change any to some (#2683) * modify one word examples to example * doc-walkthrough-content modify * limitrange-update I think it's redundant that the second to ,in order to do sth and do sth!thanks! * cluster-components-could be running could be doing sth * update cluster-components.md In theory,Master components can be run.... * update cluster-components--add a space add a space after the comma: "In theory, Master components..." * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * Revert "Highlighted command --kubectl describe" This reverts commit a70d0a3e3537c3f91b197b23f949e1e506c951d1. * kubeadm reference--change any to some kubeadm can install any add-on ? * Move Guide topics: Logging (#2687) * Disallow indexing for liveness/index (#2689) * Deprecate Guide topics. (#2691) * Wrong label and kubectl get completed pods The label `app=jobexample` should be `jobgroup=jobexample`. Also, for get completed pods the flag `--show-all` is necessary. * Update garbage-collection.md change “any” to "every" * Deprecate Guide topic: Persistent Volume Walkthrough. (#2692) * Reimplement PR #2525 Fixes typo by removing the word "controller" * remove extra space * Update multiple-schedulers doc (#2063) * Update tutorial * Fix md formatting. * Remove extraneous space * Deprecate Guide topic: Secrets Walkthrough. (#2695) * Deprecate Guide topics: quick-start ... (#2696) * Update Tasks landing page. (#2697) * Remove redundant section in deployments The status of the deployment is already covered in a later section in this doc. * Repair Spotinst logo Corrected size * fixed ASM blurb * Correct ASM logo filename * Highlighted command for `kubectl proxy`. * Update ubuntu install instructions. * Update local instructions to new method. * update init-containers.md add one word. * Minor spelling correction -- "rtk" to "rkt" * fixing typo * Doc formatting update Corrected indentation for the `nonResourcePath` and got a bit zealous with restructuring that section... * Repair Spotinst logo Corrected size * fixed ASM blurb * Correct ASM logo filename * Update garbage-collection.md change "any" to "every" * Update Weave Net's title. * fix unsupported parameter of wget command * update to be retained change "retain" to "to be retained". * Update pod.md * update init-containers.md change "a different filesystem view" to "different filesystem views". different init container should have different filesystem. * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * cluster-management--3 change 3 to three is better or not ?thanks! * fix typo 1、Parameters “--allow-verification-with-non-compliant-keys” is missed. 2、Delete the parameter "--google-json-key string"; see the "# kube-controller-manager -help" # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * fix typo 1、Delete the parameter "--google-json-key string"; 2、Parameters "--ir-data-source string"、"--ir-dbname string"、"--ir-hawkular string"、"--ir-influxdb-host string"、"--ir-namespace-only"、"--ir-password string"、"--ir-percentile int"、"--ir-user string" is missed. see the "# kube-prxoy -help" # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * Update garbage-collection.md modify the url and link * update garbage-collection.md change the url to relative path. * update out-of-resource.md change "in cases when" to "in case that" * update out-of-resource.md use a shorter and simpler expression. * update out-of-resource.md change "support" to "supports" * Create a top-level CN directory to hold future md files for the Chinese kubernetes site * Removed `=` at the end of the flags. * Remove autogenerate todo - This should be captured via a GitHub issue and not a TODO in the README documentation which leads to confusion. * Move Guide topics: Federation Tasks. (#2799) * Move Guide topics: Federation tutorial and concept. (#2802) * Move Guide topics: Federation tutorial and concept. * Add title. * Fix link. * Move kubectl Concept topics to Tutorials. (#2804) * Move kubectl Concept topics to Tutorials. * Add redirects and update links. * The calendarWrapper attribute should be unique Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Fix links. (#2808) * Fix link. (#2806) * Move topic from clusters to cluster-administration. (#2812) * Move a batch of cluster admin topics. (#2813) * Move Guide topic: Limit storage consumption. (#2814) * Move Guide topic: Limit storage consumption. * Add title. * Move Guide topic: Networking. (#2816) * Move Guide topic: Network Plugins. (#2819) * Move Guide topic: Network Plugins. * Fix link. * Move Guide topic: Static Pods. (#2820) * User Guide content migration: post notice (#2818) * Add User Guide content migration notice. * Fix formatting * Tweek formatting to block highlight text in light gray. * Try table instead of code block * remove extra lines * try table format * fix links * incorporate @ddonnelly feedback * Move Guide topic: Out of Resource. (#2821) * Move Guide topic: Monitoring Node Health. (#2822) * Move Guide topic: Monitoring Node Health. * Move to Tasks. * Move Guide topic: AppArmor. (#2823) * Apparmor (#2825) * Move Guide topic: AppArmor. * Add included files. * Move Guide topic: Audit. (#2824) * Added 1.6 Upgrade notes to outline changes for etcd 3. * Move Guide topic: Disruption Budget. (#2834) * Move Guide topic: Limit range. (#2835) * Quota (#2836) * Move Guide topic: Limit range. * Move Guide topic: Resource Quota and Limits. * Quota2 (#2838) * Move Guide topic: Limit range. * Move Guide topic: Resource Quota concept. * Dns (#2839) * Move Guide topic: Limit range. * Move Guide topic: DNS. * Delete CNAME * Create CNAME * Delete CNAME * Create CNAME * Move docs/user-guide/managing-deployments.md to /docs/concepts/cluster-administration/manage-deployment.md * add nginx-app.yaml file * add back missing / * fix link * Move Guide topic: Replication Controller Operations * Move Guide topic: Resizing a replication controller * Concepts toc (#2840) * Move Guide topic: Limit range. * Adjust Concepts Overview TOC. * Move Guide topic: Rolling Updates * Move Kubernetes API page. (#2849) * Move What is Kubernetes topic. (#2851) * Move Guide topic: Rolling Update Demo (#2850) * Move Guide topic: Rolling Update Demo * rename file * Move Guide topic: Configuration Best Practices * Move Guide topic: Jobs (#2853) * Move Guide topic: Jobs * add job.yaml file * change title * Move Pod overview. (#2865) * Move Pod overview. * Fix redirection. * Move Guide topic: Parallel Processing using Expansions (#2867) * Move Guide topic: Parallel Processing using Expansions * fix links to /docs/user-guide/jobs/ * Move Init Containers topic. (#2866) * Move Guide topic: Coarse Parallel Processing Using a Work Queue * Move Guide topic: Fine Parallel Processing using a Work Queue (#2870) * Move Guide topic: Fine Parallel Processing using a Work Queue * add migration notice * fixed capitalization * Rename /docs/tasks/job/work-queue-1/ * Move StatefulSets topic. (#2869) * Move StatefulSets topic. * Fix TOC. * Move Guide topic: Pod Templates (#2872) * Move Guide topic: Pod Templates * tweak header level and capitalization * Move PetSets topic. (#2873) * Move Garbage Collection topic. (#2874) * Move Garbage Collection topic. * Fix included file. * Move Guide topic: Prereqs * Move Guide topic: Sharing Clusters * Move Accessing Clusters topic to Concepts. (#2875) * Move Accessing Clusters topic to Concepts. * Update concepts.yml * Move Guide topic: Kubeconfig File * Move Guide topic: Config Provider Firewalls. (#2883) * Move Guide topic: Federation Service Discovery. (#2884) * Move Guide topic: Connecting Apps with Services. (#2885) * Added example and docu for hostPort ranges * Move Guide topic: Service. (#2891) * Move Guide topic: Service. * Move Guide topic: External Load Balancer. * Fix TOC. * Move Guide topic: Resource Monitoring. (#2895) * docs/admin: document OpenID Connect plugin's claim prefixing * Move Guide topic: Admin Guide * fix the command output fix the command output * Update manage-compute-resources-container.md Change "he" to "The" * update out-of-resource.md change "thresholds" to "threshold" * update init-containers.md change "apply" to "application" * amend monitor-node-health.md Amend the url link. * Fix monitor-node-health.md The url link does not exist. * fix a typo in /docs/user-guide/configmap/index.md change "value" to "values" * View $PAGE on Github without forking the repo Adding a "View docs/bla-bla.md on GitHub" button next to the "Edit docs/bla-bla.md" button so that people can view the file first without clicking the Edit button (which does not work without forking the repository). I did not need this because I was trying to do something without forking. I just found it to be bit difficult to view source of a page on GitHub. I'm open to ideas, perhaps we can instead add an article footer button named "View on GitHub" next to the "Edit this Page". Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com> * Move Guide topics: Container Lifestyle Hooks, Images, Volumes * fix to taint the master node * Add files via upload * fix the link of ogging-elasticsearch-kibana.md fix the link of url * Remove from TOC/Search: pods/init-containers ... (#2694) * Fix typo * Add files via upload * Create hyperlink Create hyperlink for kubernetes repo link. * updated PSP documentation with RBAC (#2552) Added info about controller manager setup and current implementation when using PSP with RBAC support. * Use kubectl config current-context to simplify the instructions * fix typeo (#2856) * fix typeo * Update kargo.md * Fix typo in kubectl_completion.md evaluation --> evaluated * Apply typo fixes from #2791 (#2949) * Apply typo fixes from #2791 * remove style typos * Fix the typos Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Fix typo * Fix typo (#2842)
2017-03-22 01:13:33 +00:00
The status of the init containers is returned in `status.initContainerStatuses`
field as an array of the container statuses (similar to the `status.containerStatuses`
field).
### Differences from regular Containers
Init Containers support all the fields and features of app Containers,
including resource limits, volumes, and security settings. However, the
resource requests and limits for an Init Container are handled slightly
differently, which are documented in [Resources](#resources) below. Also, Init Containers do not
support readiness probes because they must run to completion before the Pod can
be ready.
If multiple Init Containers are specified for a Pod, those Containers are run
one at a time in sequential order. Each must succeed before the next can run.
When all of the Init Containers have run to completion, Kubernetes initializes
the Pod and runs the application Containers as usual.
## What can Init Containers be used for?
Because Init Containers have separate images from app Containers, they
have some advantages for start-up related code:
* They can contain and run utilities that are not desirable to include in the
app Container image for security reasons.
* They can contain utilities or custom code for setup that is not present in an app
image. For example, there is no need to make an image `FROM` another image just to use a tool like
`sed`, `awk`, `python`, or `dig` during setup.
* The application image builder and deployer roles can work independently without
the need to jointly build a single app image.
* They use Linux namespaces so that they have different filesystem views from app Containers.
Consequently, they can be given access to Secrets that app Containers are not able to
access.
* They run to completion before any app Containers start, whereas app
Containers run in parallel, so Init Containers provide an easy way to block or
delay the startup of app Containers until some set of preconditions are met.
### Examples
Here are some ideas for how to use Init Containers:
* Wait for a service to be created with a shell command like:
for i in {1..100}; do sleep 1; if dig myservice; then exit 0; fi; exit 1
* Register this Pod with a remote server from the downward API with a command like:
curl -X POST http://$MANAGEMENT_SERVICE_HOST:$MANAGEMENT_SERVICE_PORT/register -d 'instance=$(<POD_NAME>)&ip=$(<POD_IP>)'
* Wait for some time before starting the app Container with a command like `sleep 60`.
* Clone a git repository into a volume.
* Place values into a configuration file and run a template tool to dynamically
generate a configuration file for the the main app Container. For example,
place the POD_IP value in a configuration and generate the main app
configuration file using Jinja.
More detailed usage examples can be found in the [StatefulSets documentation](/docs/concepts/abstractions/controllers/statefulsets/)
and the [Production Pods guide](/docs/user-guide/production-pods.md#handling-initialization).
### Init Containers in use
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
2017-04-28 23:03:21 +00:00
containers complete, the Pod will begin.
```yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"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;"]
}
]'
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
```
2017-05-01 17:07:15 +00:00
There is a new syntax in Kubernetes 1.6, although the old annotation syntax still works. We have moved the declaration of 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;']
```
2017-04-28 23:03:21 +00:00
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:
```
$ kubectl create -f myapp.yaml
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
Name: myapp-pod
Namespace: default
[...]
Labels: app=myapp
Status: Pending
[...]
Init Containers:
init-myservice:
[...]
State: Running
[...]
init-mydb:
[...]
2017-06-22 21:14:12 +00:00
State: Waiting
Reason: PodInitializing
Ready: False
[...]
Containers:
myapp-container:
[...]
State: Waiting
Reason: PodInitializing
Ready: False
[...]
Events:
2017-06-22 21:14:12 +00:00
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
16s 16s 1 {default-scheduler } Normal Scheduled Successfully assigned myapp-pod to 172.17.4.201
2017-06-22 21:14:12 +00:00
16s 16s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Pulling pulling image "busybox"
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Pulled Successfully pulled image "busybox"
2017-06-22 21:14:12 +00:00
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Created Created container with docker id 5ced34a04634; Security:[seccomp=unconfined]
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Started Started container with docker id 5ced34a04634
$ kubectl logs myapp-pod -c init-myservice # Inspect the first init container
$ kubectl logs myapp-pod -c init-mydb # Inspect the second init container
```
2017-04-28 23:03:21 +00:00
Once we start the `mydb` and `myservice` services, we can see the Init Containers
complete and the `myapp-pod` is created:
```
$ kubectl create -f services.yaml
service "myservice" created
service "mydb" created
$ kubectl get -f myapp.yaml
NAME READY STATUS RESTARTS AGE
myapp-pod 1/1 Running 0 9m
```
This example is very simple but should provide some inspiration for you to
create your own Init Containers.
## Detailed behavior
During the startup of a Pod, the Init Containers are started in order, after the
network and volumes are initialized. Each Container must exit successfully before
the next is started. If a Container fails to start due to the runtime or
exits with failure, it is retried according to the Pod `restartPolicy`. However,
if the Pod `restartPolicy` is set to Always, the Init Containers use
`RestartPolicy` OnFailure.
A Pod cannot be `Ready` until all Init Containers have succeeded. The ports on an
Init Container are not aggregated under a service. A Pod that is initializing
is in the `Pending` state but should have a condition `Initializing` set to true.
If the Pod is [restarted](#pod-restart-reasons), all Init Containers must
execute again.
Changes to the Init Container spec are limited to the container image field.
Altering an Init Container image field is equivalent to restarting the Pod.
Because Init Containers can be restarted, retried, or re-executed, Init Container
code should be idempotent. In particular, code that writes to files on `EmptyDirs`
should be prepared for the possibility that an output file already exists.
Init Containers have all of the fields of an app Container. However, Kubernetes
prohibits `readinessProbe` from being used because Init Containers cannot
define readiness distinct from completion. This is enforced during validation.
Use `activeDeadlineSeconds` on the Pod and `livenessProbe` on the Container to
prevent Init Containers from failing forever. The active deadline includes Init
Containers.
The name of each app and Init Container in a Pod must be unique; a
validation error is thrown for any Container sharing a name with another.
### Resources
Given the ordering and execution for Init Containers, the following rules
2017-03-22 06:03:14 +00:00
for resource usage apply:
* The highest of any particular resource request or limit defined on all Init
Containers is the *effective init request/limit*
* The Pod's *effective request/limit* for a resource is the higher of:
* the sum of all app Containers request/limit for a resource
* the effective init request/limit for a resource
* Scheduling is done based on effective requests/limits, which means
Init Containers can reserve resources for initialization that are not used
during the life of the Pod.
* QoS tier of the Pod's *effective QoS tier* is the QoS tier for Init Containers
and app containers alike.
Quota and limits are applied based on the effective Pod request and
limit.
Pod level cgroups are based on the effective Pod request and limit, the
same as the scheduler.
### Pod restart reasons
A Pod can restart, causing re-execution of Init Containers, for the following
reasons:
* A user updates the PodSpec causing the Init Container image to change.
App Container image changes only restart the app Container.
* The Pod infrastructure container is restarted. This is uncommon and would
have to be done by someone with root access to nodes.
* All containers in a Pod are terminated while `restartPolicy` is set to Always,
forcing a restart, and the Init Container completion record has been lost due
to garbage collection.
## Support and compatibility
Move init containers to stable in v1.6 (#1939) * Delete the parameter "--google-json-key string" Delete the parameter "--google-json-key string" * Fix apimachinery vendored dependencies in examples_test. * package apt-transport-https should be installed Ubuntu default install not include apt-transport-https. so if you want to download package from https repo, you need install apt-transport-https package first * doc-walkthrough-content modify * limitrange-update I think it's redundant that the second to ,in order to do sth and do sth!thanks! * fix command kubectl get svc,pod output fix command kubectl get svc,pod output * Fix typo: federation-controller-mananger => federation-controller-manager * Fix typo: federation-controller-mananger => federation-controller-manager * Clarify minimum version of kubernetes supporting PSP authz * Provide correct location for KUBE_ETCD_SERVERS Provide correct location for KUBE_ETCD_SERVERS configuration key. It was previously listed as being in /etc/kubernetes/config but is actually in /etc/kubernetes/apiserver. Related: https://github.com/kubernetes/kubernetes.github.io/issues/1600 * Move Compute Resources topic to Concepts. (#2410) * Delete the parameter "--google-json-key string" “# kube-scheduler -help”can not find --google-json-key option # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * Add diagnose tips when you face problem. * Update grammar for kubeadm.md, thanks @chenopis * Merge two pieces to one words * add http proxy infomation in kubeadm * Update landing pages for Tasks and Tutorials. (#2634) * Update static-pods.md It works. Please review it again. * Move Guide Topic: Multi-container pods. (#2642) * fix link to go to pod-lifecycle page * fix the command output fix the command output * mirantis_logo.png ,/images/community_logos/mirantis_logo.png updated per Mirantis request * kubeadm reference -- / set up/manage mean set up or manage ? it's better use or? * Prototype for deprecating User Guide topic. * missing word The return of the OCD. * Move Guide topic: Using Environment Variables. (#2645) * fix typo (#2656) fix typo * Move Guide topic: Using Port Forwarding. (#2661) * Move Guide topic: Bootstrapping Pet Sets. (#2662) * Move Guide topic: Bootstrapping Pet Sets. * Add TOC entry. * Move Guide topic: Connect with Proxies. (#2663) * Move Guide topic: Connect with Proxies. * Fix link. * add DefaultTolerationSeconds admission controller * getting-started-guides: add CoreOS Tectonic * Correct the certificate name * Update index.md * Update installation.md * Update validation.md * Update backups.md * Update backups.md * Spell fixes * Using it vs Juju Kubernetes * Q1 update to k8s tech and service partner list New partners registered to K8s Partner Ecosystem sign-up form. Logo updates companion to this edit still WIP * Logo file updates for new registrants Logos for new registrants * The attribute [allowfullscree] must have a value Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Remove newline before passing to base64 * Use single quote to avoid string interpolation, update output * Update command as files contain no newline * Remove all dead links, use just filename As user can guess that it is file copied from the shown content * Fix link to dev guide. * Add --leader-elect=false Second scheduler could not start without disabling leader-elect. * cluster-components-could be running could be doing sth * update cluster-components.md In theory,Master components can be run.... * update cluster-components--add a space add a space after the comma: "In theory, Master components..." * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * Revert "Highlighted command --kubectl describe" This reverts commit a70d0a3e3537c3f91b197b23f949e1e506c951d1. * Add example show how to configure proxy for kube * Revision as the suggestion describe * move ha-master-gce.png to images/docs Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * use relative path for ha-master-gce image Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * The attribute [calendarWrapper] must be unique Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * add required images in kubeadm init step * Add links to Docker/rtk in cluster-intro.html * s/acomplish/accomplish/ * Modify the link URL of [kubelet eviction design doc] [kubelet eviction design doc] should be linked to kubernetes.github.io instead of community/design-proposal. * fix CronJob object name fix CronJob object name * remove redundant a Signed-off-by: Xiuyu Li <nickleefly@gmail.com> * kubeadm reference--change any to some (#2683) * modify one word examples to example * doc-walkthrough-content modify * limitrange-update I think it's redundant that the second to ,in order to do sth and do sth!thanks! * cluster-components-could be running could be doing sth * update cluster-components.md In theory,Master components can be run.... * update cluster-components--add a space add a space after the comma: "In theory, Master components..." * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * Revert "Highlighted command --kubectl describe" This reverts commit a70d0a3e3537c3f91b197b23f949e1e506c951d1. * kubeadm reference--change any to some kubeadm can install any add-on ? * Move Guide topics: Logging (#2687) * Disallow indexing for liveness/index (#2689) * Deprecate Guide topics. (#2691) * Wrong label and kubectl get completed pods The label `app=jobexample` should be `jobgroup=jobexample`. Also, for get completed pods the flag `--show-all` is necessary. * Update garbage-collection.md change “any” to "every" * Deprecate Guide topic: Persistent Volume Walkthrough. (#2692) * Reimplement PR #2525 Fixes typo by removing the word "controller" * remove extra space * Update multiple-schedulers doc (#2063) * Update tutorial * Fix md formatting. * Remove extraneous space * Deprecate Guide topic: Secrets Walkthrough. (#2695) * Deprecate Guide topics: quick-start ... (#2696) * Update Tasks landing page. (#2697) * Remove redundant section in deployments The status of the deployment is already covered in a later section in this doc. * Repair Spotinst logo Corrected size * fixed ASM blurb * Correct ASM logo filename * Highlighted command for `kubectl proxy`. * Update ubuntu install instructions. * Update local instructions to new method. * update init-containers.md add one word. * Minor spelling correction -- "rtk" to "rkt" * fixing typo * Doc formatting update Corrected indentation for the `nonResourcePath` and got a bit zealous with restructuring that section... * Repair Spotinst logo Corrected size * fixed ASM blurb * Correct ASM logo filename * Update garbage-collection.md change "any" to "every" * Update Weave Net's title. * fix unsupported parameter of wget command * update to be retained change "retain" to "to be retained". * Update pod.md * update init-containers.md change "a different filesystem view" to "different filesystem views". different init container should have different filesystem. * Highlighted command --kubectl describe In web page ,there is no space ,need some empty space,thanks! * cluster-management--3 change 3 to three is better or not ?thanks! * fix typo 1、Parameters “--allow-verification-with-non-compliant-keys” is missed. 2、Delete the parameter "--google-json-key string"; see the "# kube-controller-manager -help" # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * fix typo 1、Delete the parameter "--google-json-key string"; 2、Parameters "--ir-data-source string"、"--ir-dbname string"、"--ir-hawkular string"、"--ir-influxdb-host string"、"--ir-namespace-only"、"--ir-password string"、"--ir-percentile int"、"--ir-user string" is missed. see the "# kube-prxoy -help" # kubectl version Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-23T00:04:39Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"f5ef9802914a47c848fd84c287333f8b4d28bbc1", GitTreeState:"dirty", BuildDate:"2017-01-22T23:56:57Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64", USEEVersion:"V1.02.01_alpha", USEEPublishDate:"2017-1-10 00:00:00"} * Update garbage-collection.md modify the url and link * update garbage-collection.md change the url to relative path. * update out-of-resource.md change "in cases when" to "in case that" * update out-of-resource.md use a shorter and simpler expression. * update out-of-resource.md change "support" to "supports" * Create a top-level CN directory to hold future md files for the Chinese kubernetes site * Removed `=` at the end of the flags. * Remove autogenerate todo - This should be captured via a GitHub issue and not a TODO in the README documentation which leads to confusion. * Move Guide topics: Federation Tasks. (#2799) * Move Guide topics: Federation tutorial and concept. (#2802) * Move Guide topics: Federation tutorial and concept. * Add title. * Fix link. * Move kubectl Concept topics to Tutorials. (#2804) * Move kubectl Concept topics to Tutorials. * Add redirects and update links. * The calendarWrapper attribute should be unique Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Fix links. (#2808) * Fix link. (#2806) * Move topic from clusters to cluster-administration. (#2812) * Move a batch of cluster admin topics. (#2813) * Move Guide topic: Limit storage consumption. (#2814) * Move Guide topic: Limit storage consumption. * Add title. * Move Guide topic: Networking. (#2816) * Move Guide topic: Network Plugins. (#2819) * Move Guide topic: Network Plugins. * Fix link. * Move Guide topic: Static Pods. (#2820) * User Guide content migration: post notice (#2818) * Add User Guide content migration notice. * Fix formatting * Tweek formatting to block highlight text in light gray. * Try table instead of code block * remove extra lines * try table format * fix links * incorporate @ddonnelly feedback * Move Guide topic: Out of Resource. (#2821) * Move Guide topic: Monitoring Node Health. (#2822) * Move Guide topic: Monitoring Node Health. * Move to Tasks. * Move Guide topic: AppArmor. (#2823) * Apparmor (#2825) * Move Guide topic: AppArmor. * Add included files. * Move Guide topic: Audit. (#2824) * Added 1.6 Upgrade notes to outline changes for etcd 3. * Move Guide topic: Disruption Budget. (#2834) * Move Guide topic: Limit range. (#2835) * Quota (#2836) * Move Guide topic: Limit range. * Move Guide topic: Resource Quota and Limits. * Quota2 (#2838) * Move Guide topic: Limit range. * Move Guide topic: Resource Quota concept. * Dns (#2839) * Move Guide topic: Limit range. * Move Guide topic: DNS. * Delete CNAME * Create CNAME * Delete CNAME * Create CNAME * Move docs/user-guide/managing-deployments.md to /docs/concepts/cluster-administration/manage-deployment.md * add nginx-app.yaml file * add back missing / * fix link * Move Guide topic: Replication Controller Operations * Move Guide topic: Resizing a replication controller * Concepts toc (#2840) * Move Guide topic: Limit range. * Adjust Concepts Overview TOC. * Move Guide topic: Rolling Updates * Move Kubernetes API page. (#2849) * Move What is Kubernetes topic. (#2851) * Move Guide topic: Rolling Update Demo (#2850) * Move Guide topic: Rolling Update Demo * rename file * Move Guide topic: Configuration Best Practices * Move Guide topic: Jobs (#2853) * Move Guide topic: Jobs * add job.yaml file * change title * Move Pod overview. (#2865) * Move Pod overview. * Fix redirection. * Move Guide topic: Parallel Processing using Expansions (#2867) * Move Guide topic: Parallel Processing using Expansions * fix links to /docs/user-guide/jobs/ * Move Init Containers topic. (#2866) * Move Guide topic: Coarse Parallel Processing Using a Work Queue * Move Guide topic: Fine Parallel Processing using a Work Queue (#2870) * Move Guide topic: Fine Parallel Processing using a Work Queue * add migration notice * fixed capitalization * Rename /docs/tasks/job/work-queue-1/ * Move StatefulSets topic. (#2869) * Move StatefulSets topic. * Fix TOC. * Move Guide topic: Pod Templates (#2872) * Move Guide topic: Pod Templates * tweak header level and capitalization * Move PetSets topic. (#2873) * Move Garbage Collection topic. (#2874) * Move Garbage Collection topic. * Fix included file. * Move Guide topic: Prereqs * Move Guide topic: Sharing Clusters * Move Accessing Clusters topic to Concepts. (#2875) * Move Accessing Clusters topic to Concepts. * Update concepts.yml * Move Guide topic: Kubeconfig File * Move Guide topic: Config Provider Firewalls. (#2883) * Move Guide topic: Federation Service Discovery. (#2884) * Move Guide topic: Connecting Apps with Services. (#2885) * Added example and docu for hostPort ranges * Move Guide topic: Service. (#2891) * Move Guide topic: Service. * Move Guide topic: External Load Balancer. * Fix TOC. * Move Guide topic: Resource Monitoring. (#2895) * docs/admin: document OpenID Connect plugin's claim prefixing * Move Guide topic: Admin Guide * fix the command output fix the command output * Update manage-compute-resources-container.md Change "he" to "The" * update out-of-resource.md change "thresholds" to "threshold" * update init-containers.md change "apply" to "application" * amend monitor-node-health.md Amend the url link. * Fix monitor-node-health.md The url link does not exist. * fix a typo in /docs/user-guide/configmap/index.md change "value" to "values" * View $PAGE on Github without forking the repo Adding a "View docs/bla-bla.md on GitHub" button next to the "Edit docs/bla-bla.md" button so that people can view the file first without clicking the Edit button (which does not work without forking the repository). I did not need this because I was trying to do something without forking. I just found it to be bit difficult to view source of a page on GitHub. I'm open to ideas, perhaps we can instead add an article footer button named "View on GitHub" next to the "Edit this Page". Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com> * Move Guide topics: Container Lifestyle Hooks, Images, Volumes * fix to taint the master node * Add files via upload * fix the link of ogging-elasticsearch-kibana.md fix the link of url * Remove from TOC/Search: pods/init-containers ... (#2694) * Fix typo * Add files via upload * Create hyperlink Create hyperlink for kubernetes repo link. * updated PSP documentation with RBAC (#2552) Added info about controller manager setup and current implementation when using PSP with RBAC support. * Use kubectl config current-context to simplify the instructions * fix typeo (#2856) * fix typeo * Update kargo.md * Fix typo in kubectl_completion.md evaluation --> evaluated * Apply typo fixes from #2791 (#2949) * Apply typo fixes from #2791 * remove style typos * Fix the typos Signed-off-by: yupengzte <yu.peng36@zte.com.cn> * Fix typo * Fix typo (#2842)
2017-03-22 01:13:33 +00:00
A cluster with Apiserver version 1.6.0 or greater supports Init Containers
using the `spec.initContainers` field. Previous versions support Init Containers
using the alpha or beta annotations. The `spec.initContainers` field is also mirrored
into alpha and beta annotations so that Kubelets version 1.3.0 or greater can execute
Init Containers, and so that a version 1.6 apiserver can safely be rolled back to version
1.5.x without losing Init Container functionality for existing created pods.
{% endcapture %}
{% capture whatsnext %}
* [Creating a Pod that has an Init Container](/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container)
{% endcapture %}
{% include templates/concept.md %}