2015-07-14 08:13:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								<!--  BEGIN MUNGE: UNVERSIONED_WARNING  --> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								<!--  BEGIN STRIP_FOR_RELEASE  --> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 01:02:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								< img  src = "http://kubernetes.io/img/warning.png"  alt = "WARNING" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     width="25" height="25">
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< img  src = "http://kubernetes.io/img/warning.png"  alt = "WARNING" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     width="25" height="25">
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< img  src = "http://kubernetes.io/img/warning.png"  alt = "WARNING" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     width="25" height="25">
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< img  src = "http://kubernetes.io/img/warning.png"  alt = "WARNING" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     width="25" height="25">
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< img  src = "http://kubernetes.io/img/warning.png"  alt = "WARNING" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     width="25" height="25">
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								If you are using a released version of Kubernetes, you should
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								refer to the docs that go with that version.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< strong > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The latest 1.0.x release of this document can be found
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[here ](http://releases.k8s.io/release-1.0/docs/user-guide/walkthrough/README.md ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Documentation for other releases can be found at
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[releases.k8s.io ](http://releases.k8s.io ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / strong > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								--
							 
						 
					
						
							
								
									
										
										
										
											2015-07-14 06:15:35 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-14 08:13:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								<!--  END STRIP_FOR_RELEASE  --> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								<!--  END MUNGE: UNVERSIONED_WARNING  --> 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-18 06:35:41 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Kubernetes 101 - Kubectl CLI and Pods
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								For Kubernetes 101, we will cover kubectl, pods, volumes, and multiple containers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-03 22:10:11 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In order for the kubectl usage examples to work, make sure you have an examples directory locally, either from [a release ](https://github.com/kubernetes/kubernetes/releases ) or [the source ](https://github.com/kubernetes/kubernetes ).
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								**Table of Contents**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								<!--  BEGIN MUNGE: GENERATED_TOC  --> 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-18 00:20:19 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								-  [Kubernetes 101 - Kubectl CLI and Pods ](#kubernetes-101---kubectl-cli-and-pods )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  [Kubectl CLI ](#kubectl-cli )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  [Pods ](#pods )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      -  [Pod Definition ](#pod-definition )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      -  [Pod Management ](#pod-management )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      -  [Volumes ](#volumes )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        -  [Volume Types ](#volume-types )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      -  [Multiple Containers ](#multiple-containers )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  [What's Next? ](#whats-next )
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								<!--  END MUNGE: GENERATED_TOC  --> 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Kubectl CLI
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The easiest way to interact with Kubernetes is via the [kubectl ](../kubectl/kubectl.md ) command-line interface.
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								For more info about kubectl, including its usage, commands, and parameters, see the [kubectl CLI reference ](../kubectl/kubectl.md ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								If you haven't installed and configured kubectl, finish the [prerequisites ](../prereqs.md ) before continuing.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Pods
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-18 06:35:41 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In Kubernetes, a group of one or more containers is called a _pod_ . Containers in a pod are deployed together, and are started, stopped, and replicated as a group.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								See [pods ](../../../docs/user-guide/pods.md ) for more details.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#### Pod Definition
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The simplest pod definition describes the deployment of a single container.  For example, an nginx web server pod might be defined as such:
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```yaml
							 
						 
					
						
							
								
									
										
										
										
											2015-06-11 04:25:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								apiVersion: v1
							 
						 
					
						
							
								
									
										
										
										
											2014-12-26 01:07:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								kind: Pod
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								metadata:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  name: nginx
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								spec:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  containers:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  -  name: nginx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    image: nginx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ports:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  containerPort: 80
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								A pod definition is a declaration of a _desired state_ .  Desired state is a very important concept in the Kubernetes model.  Many things present a desired state to the system, and it is Kubernetes' responsibility to make sure that the current state matches the desired state.  For example, when you create a Pod, you declare that you want the containers in it to be running.  If the containers happen to not be running (e.g. program failure, ...), Kubernetes will continue to (re-)create them for you in order to drive them to the desired state. This process continues until the Pod is deleted.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 05:33:35 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								See the [design document ](../../design/README.md ) for more details.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#### Pod Management
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Create a pod containing an nginx server ([pod-nginx.yaml](pod-nginx.yaml)):
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```sh
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$ kubectl create -f docs/user-guide/walkthrough/pod-nginx.yaml
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								List all pods:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```sh
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$ kubectl get pods
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								On most providers, the pod IPs are not externally accessible. The easiest way to test that the pod is working is to create a busybox pod and exec commands on it remotely. See the [command execution documentation ](../kubectl/kubectl_exec.md ) for details.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Provided the pod IP is accessible, you should be able to access its http endpoint with curl on port 80:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```sh
							 
						 
					
						
							
								
									
										
										
										
											2015-08-21 21:09:41 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$ curl http://$(kubectl get pod nginx -o go-template={{.status.podIP}})
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Delete the pod by name:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```sh
							 
						 
					
						
							
								
									
										
										
										
											2015-07-17 04:49:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$ kubectl delete pod nginx
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### Volumes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								That's great for a simple static web server, but what about persistent storage?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The container file system only lives as long as the container does. So if your app's state needs to survive relocation, reboots, and crashes, you'll need to configure some persistent storage.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:52:14 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								For this example we'll be creating a Redis pod with a named volume and volume mount that defines the path to mount the volume.
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								1.  Define a volume:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ```yaml
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    volumes:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  name: redis-persistent-storage
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      emptyDir: {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:52:14 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								2.  Define a volume mount within a container definition:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ```yaml
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    volumeMounts:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # name must match the volume name below
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  name: redis-persistent-storage
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      # mount path within the container
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      mountPath: /data/redis
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Example Redis pod definition with a persistent storage volume ([pod-redis.yaml](pod-redis.yaml)):
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:46:20 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								<!--  BEGIN MUNGE: EXAMPLE pod - redis.yaml  --> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```yaml
							 
						 
					
						
							
								
									
										
										
										
											2015-06-11 04:25:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								apiVersion: v1
							 
						 
					
						
							
								
									
										
										
										
											2014-12-26 01:07:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								kind: Pod
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								metadata:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  name: redis
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								spec:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  containers:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  -  name: redis
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    image: redis
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    volumeMounts:
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    -  name: redis-persistent-storage
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      mountPath: /data/redis
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  volumes:
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  -  name: redis-persistent-storage
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    emptyDir: {}
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:46:20 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[Download example ](pod-redis.yaml )
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 01:45:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								<!--  END MUNGE: EXAMPLE pod - redis.yaml  --> 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:46:20 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Notes:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								-  The volume mount name is a reference to a specific empty dir volume.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								-  The volume mount path is the path to mount the empty dir volume within the container.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								##### Volume Types
 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								-  **EmptyDir**: Creates a new directory that will persist across container failures and restarts.
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 06:52:14 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								-  **HostPath**: Mounts an existing directory on the node's file system (e.g. `/var/logs` ).
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								See [volumes ](../../../docs/user-guide/volumes.md ) for more details.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### Multiple Containers
 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								_Note:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The examples below are syntactically correct, but some of the images (e.g. kubernetes/git-monitor) don't exist yet.  We're working on turning these into working examples._
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								However, often you want to have two different containers that work together.  An example of this would be a web server, and a helper job that polls a git repository for new updates:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```yaml
							 
						 
					
						
							
								
									
										
										
										
											2015-06-11 04:25:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								apiVersion: v1
							 
						 
					
						
							
								
									
										
										
										
											2014-12-26 01:07:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								kind: Pod
							 
						 
					
						
							
								
									
										
										
										
											2015-05-08 08:55:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								metadata:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  name: www
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								spec:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  containers:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  name: nginx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    image: nginx
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    volumeMounts:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  mountPath: /srv/www
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      name: www-data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      readOnly: true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  name: git-monitor
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    image: kubernetes/git-monitor
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    env:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  name: GIT_REPO
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      value: http://github.com/some/repo.git
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    volumeMounts:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    -  mountPath: /data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      name: www-data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  volumes:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  -  name: www-data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    emptyDir: {}
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Note that we have also added a volume here.  In this case, the volume is mounted into both containers.  It is marked `readOnly`  in the web server's case, since it doesn't need to write to the directory.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Finally, we have also introduced an environment variable to the `git-monitor`  container, which allows us to parameterize that container with the particular git repository that we want to track.
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 04:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## What's Next?
 
							 
						 
					
						
							
								
									
										
										
										
											2014-09-19 05:44:37 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-14 08:13:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								Continue on to [Kubernetes 201 ](k8s201.md ) or
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								for a complete application see the [guestbook example ](../../../examples/guestbook/README.md )
							 
						 
					
						
							
								
									
										
										
										
											2015-05-15 06:12:45 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-14 08:13:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								<!--  BEGIN MUNGE: GENERATED_ANALYTICS  --> 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-15 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[]()
							 
						 
					
						
							
								
									
										
										
										
											2015-07-14 08:13:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								<!--  END MUNGE: GENERATED_ANALYTICS  -->