Merge remote-tracking branch 'origin/master'

This commit is contained in:
scotty 2016-03-29 11:52:14 -07:00
commit d0f9e5a243
11 changed files with 228 additions and 195 deletions

View File

@ -95,16 +95,16 @@ were previously created in a namespace.
If a resource (cpu or memory) is being restricted by a limit, the user will get an error at time If a resource (cpu or memory) is being restricted by a limit, the user will get an error at time
of creation explaining why. of creation explaining why.
Let's first spin up a replication controller that creates a single container pod to demonstrate Let's first spin up a deployment that creates a single container pod to demonstrate
how default values are applied to each pod. how default values are applied to each pod.
```shell ```shell
$ kubectl run nginx --image=nginx --replicas=1 --namespace=limit-example $ kubectl run nginx --image=nginx --replicas=1 --namespace=limit-example
replicationcontroller "nginx" created deployment "nginx" created
$ kubectl get pods --namespace=limit-example $ kubectl get pods --namespace=limit-example
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
nginx-aq0mf 1/1 Running 0 35s nginx-2040093540-s8vzu 1/1 Running 0 11s
$ kubectl get pods nginx-aq0mf --namespace=limit-example -o yaml | grep resources -C 8 $ kubectl get pods nginx-2040093540-s8vzu --namespace=limit-example -o yaml | grep resources -C 8
``` ```
```yaml ```yaml
@ -191,4 +191,4 @@ default <none> Active 20m
Cluster operators that want to restrict the amount of resources a single container or pod may consume Cluster operators that want to restrict the amount of resources a single container or pod may consume
are able to define allowable ranges per Kubernetes namespace. In the absence of any explicit assignments, are able to define allowable ranges per Kubernetes namespace. In the absence of any explicit assignments,
the Kubernetes system is able to apply default resource *limits* and *requests* if desired in order to the Kubernetes system is able to apply default resource *limits* and *requests* if desired in order to
constrain the amount of resource a pod consumes on a node. constrain the amount of resource a pod consumes on a node.

View File

@ -17,12 +17,12 @@ This example demonstrates how to use Kubernetes namespaces to subdivide your clu
This example assumes the following: This example assumes the following:
1. You have an [existing Kubernetes cluster](/docs/getting-started-guides/). 1. You have an [existing Kubernetes cluster](/docs/getting-started-guides/).
2. You have a basic understanding of Kubernetes _[pods](/docs/user-guide/pods)_, _[services](/docs/user-guide/services)_, and _[replication controllers](/docs/user-guide/replication-controller)_. 2. You have a basic understanding of Kubernetes _[Pods](/docs/user-guide/pods)_, _[Services](/docs/user-guide/services)_, and _[Deployments](/docs/user-guide/deployments)_.
### Step One: Understand the default namespace ### Step One: Understand the default namespace
By default, a Kubernetes cluster will instantiate a default namespace when provisioning the cluster to hold the default set of pods, By default, a Kubernetes cluster will instantiate a default namespace when provisioning the cluster to hold the default set of Pods,
services, and replication controllers used by the cluster. Services, and Deployments used by the cluster.
Assuming you have a fresh cluster, you can introspect the available namespace's by doing the following: Assuming you have a fresh cluster, you can introspect the available namespace's by doing the following:
@ -38,12 +38,12 @@ For this exercise, we will create two additional Kubernetes namespaces to hold o
Let's imagine a scenario where an organization is using a shared Kubernetes cluster for development and production use cases. Let's imagine a scenario where an organization is using a shared Kubernetes cluster for development and production use cases.
The development team would like to maintain a space in the cluster where they can get a view on the list of pods, services, and replication controllers The development team would like to maintain a space in the cluster where they can get a view on the list of Pods, Services, and Deployments
they use to build and run their application. In this space, Kubernetes resources come and go, and the restrictions on who can or cannot modify resources they use to build and run their application. In this space, Kubernetes resources come and go, and the restrictions on who can or cannot modify resources
are relaxed to enable agile development. are relaxed to enable agile development.
The operations team would like to maintain a space in the cluster where they can enforce strict procedures on who can or cannot manipulate the set of The operations team would like to maintain a space in the cluster where they can enforce strict procedures on who can or cannot manipulate the set of
pods, services, and replication controllers that run the production site. pods, services, and Deployments that run the production site.
One pattern this organization could follow is to partition the Kubernetes cluster into two namespaces: development and production. One pattern this organization could follow is to partition the Kubernetes cluster into two namespaces: development and production.
@ -77,11 +77,11 @@ production name=production Active
### Step Three: Create pods in each namespace ### Step Three: Create pods in each namespace
A Kubernetes namespace provides the scope for pods, services, and replication controllers in the cluster. A Kubernetes namespace provides the scope for Pods, Services, and Deployments in the cluster.
Users interacting with one namespace do not see the content in another namespace. Users interacting with one namespace do not see the content in another namespace.
To demonstrate this, let's spin up a simple replication controller and pod in the development namespace. To demonstrate this, let's spin up a simple Deployment and Pods in the development namespace.
We first check what is the current context: We first check what is the current context:
@ -178,18 +178,18 @@ Let's create some content.
```shell ```shell
$ kubectl run snowflake --image=kubernetes/serve_hostname --replicas=2 $ kubectl run snowflake --image=kubernetes/serve_hostname --replicas=2
``` ```
We have just created a deployment whose replica size is 2 that is running the pod called snowflake with a basic container that just serves the hostname.
We have just created a replication controller whose replica size is 2 that is running the pod called snowflake with a basic container that just serves the hostname. Note that `kubectl run` creates deployments only on kubernetes cluster >= v1.2. If you are running older versions, it creates replication controllers instead.
```shell ```shell
$ kubectl get rc $ kubectl get deployment
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
snowflake snowflake kubernetes/serve_hostname run=snowflake 2 snowflake 2 2 2 2 2m
$ kubectl get pods $ kubectl get pods -l run=snowflake
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
snowflake-8w0qn 1/1 Running 0 22s snowflake-3968820950-9dgr8 1/1 Running 0 2m
snowflake-jrpzb 1/1 Running 0 22s snowflake-3968820950-vgc4n 1/1 Running 0 2m
``` ```
And this is great, developers are able to do what they want, and they do not have to worry about affecting content in the production namespace. And this is great, developers are able to do what they want, and they do not have to worry about affecting content in the production namespace.
@ -200,14 +200,11 @@ Let's switch to the production namespace and show how resources in one namespace
$ kubectl config use-context prod $ kubectl config use-context prod
``` ```
The production namespace should be empty. The production namespace should be empty, and the following commands should return nothing.
```shell ```shell
$ kubectl get rc $ kubectl get deployment
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
$ kubectl get pods $ kubectl get pods
NAME READY STATUS RESTARTS AGE
``` ```
Production likes to run cattle, so let's create some cattle pods. Production likes to run cattle, so let's create some cattle pods.
@ -215,17 +212,17 @@ Production likes to run cattle, so let's create some cattle pods.
```shell ```shell
$ kubectl run cattle --image=kubernetes/serve_hostname --replicas=5 $ kubectl run cattle --image=kubernetes/serve_hostname --replicas=5
$ kubectl get rc $ kubectl get deployment
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
cattle cattle kubernetes/serve_hostname run=cattle 5 cattle 5 5 5 5 10s
$ kubectl get pods kubectl get pods -l run=cattle
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
cattle-97rva 1/1 Running 0 12s cattle-2263376956-41xy6 1/1 Running 0 34s
cattle-i9ojn 1/1 Running 0 12s cattle-2263376956-kw466 1/1 Running 0 34s
cattle-qj3yv 1/1 Running 0 12s cattle-2263376956-n4v97 1/1 Running 0 34s
cattle-yc7vn 1/1 Running 0 12s cattle-2263376956-p5p3i 1/1 Running 0 34s
cattle-zz7ea 1/1 Running 0 12s cattle-2263376956-sxpth 1/1 Running 0 34s
``` ```
At this point, it should be clear that the resources users create in one namespace are hidden from the other namespace. At this point, it should be clear that the resources users create in one namespace are hidden from the other namespace.

View File

@ -69,38 +69,40 @@ Pod authors rarely specify resource requests and limits for their pods.
Since we applied a quota to our project, let's see what happens when an end-user creates a pod that has unbounded Since we applied a quota to our project, let's see what happens when an end-user creates a pod that has unbounded
cpu and memory by creating an nginx container. cpu and memory by creating an nginx container.
To demonstrate, lets create a replication controller that runs nginx: To demonstrate, lets create a Deployment that runs nginx:
```shell ```shell
$ kubectl run nginx --image=nginx --replicas=1 --namespace=quota-example $ kubectl run nginx --image=nginx --replicas=1 --namespace=quota-example
replicationcontroller "nginx" created deployment "nginx" created
``` ```
Now let's look at the pods that were created. This creates a Deployment "nginx" with its underlying resource, a ReplicaSet, which handles the creation and deletion of Pod replicas. Now let's look at the pods that were created.
```shell ```shell
$ kubectl get pods --namespace=quota-example $ kubectl get pods --namespace=quota-example
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
``` ```
What happened? I have no pods! Let's describe the replication controller to get a view of what is happening. What happened? I have no pods! Let's describe the ReplicaSet managed by the nginx Deployment to get a view of what is happening.
Note that `kubectl describe rs` works only on kubernetes cluster >= v1.2. If you are running older versions, use `kubectl describe rc` instead.
```shell ```shell
kubectl describe rc nginx --namespace=quota-example $ kubectl describe rs -l run=nginx --namespace=quota-example
Name: nginx Name: nginx-2040093540
Namespace: quota-example Namespace: quota-example
Image(s): nginx Image(s): nginx
Selector: run=nginx Selector: pod-template-hash=2040093540,run=nginx
Labels: run=nginx Labels: pod-template-hash=2040093540,run=nginx
Replicas: 0 current / 1 desired Replicas: 0 current / 1 desired
Pods Status: 0 Running / 0 Waiting / 0 Succeeded / 0 Failed Pods Status: 0 Running / 0 Waiting / 0 Succeeded / 0 Failed
No volumes. No volumes.
Events: Events:
FirstSeen LastSeen Count From SubobjectPath Reason Message FirstSeen LastSeen Count From SubobjectPath Type Reason Message
42s 11s 3 {replication-controller } FailedCreate Error creating: Pod "nginx-" is forbidden: Must make a non-zero request for memory since it is tracked by quota. --------- -------- ----- ---- ------------- -------- ------ -------
48s 26s 4 {replicaset-controller } Warning FailedCreate Error creating: pods "nginx-2040093540-" is forbidden: Failed quota: quota: must specify cpu,memory
``` ```
The Kubernetes API server is rejecting the replication controllers requests to create a pod because our pods The Kubernetes API server is rejecting the ReplicaSet requests to create a pod because our pods
do not specify any memory usage *request*. do not specify any memory usage *request*.
So let's set some default values for the amount of cpu and memory a pod can consume: So let's set some default values for the amount of cpu and memory a pod can consume:
@ -111,22 +113,22 @@ limitrange "limits" created
$ kubectl describe limits limits --namespace=quota-example $ kubectl describe limits limits --namespace=quota-example
Name: limits Name: limits
Namespace: quota-example Namespace: quota-example
Type Resource Min Max Request Limit Limit/Request Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
---- -------- --- --- ------- ----- ------------- ---- -------- --- --- --------------- ------------- -----------------------
Container memory - - 256Mi 512Mi - Container cpu - - 100m 200m -
Container cpu - - 100m 200m - Container memory - - 256Mi 512Mi -
``` ```
Now any time a pod is created in this namespace, if it has not specified any resource request/limit, the default Now any time a pod is created in this namespace, if it has not specified any resource request/limit, the default
amount of cpu and memory per container will be applied, and the request will be used as part of admission control. amount of cpu and memory per container will be applied, and the request will be used as part of admission control.
Now that we have applied default resource *request* for our namespace, our replication controller should be able to Now that we have applied default resource *request* for our namespace, our Deployment should be able to
create its pods. create its pods.
```shell ```shell
$ kubectl get pods --namespace=quota-example $ kubectl get pods --namespace=quota-example
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
nginx-fca65 1/1 Running 0 1m nginx-2040093540-miohp 1/1 Running 0 5s
``` ```
And if we print out our quota usage in the namespace: And if we print out our quota usage in the namespace:
@ -153,4 +155,4 @@ You can now see the pod that was created is consuming explicit amounts of resour
Actions that consume node resources for cpu and memory can be subject to hard quota limits defined by the namespace quota. The resource consumption is measured by resource *request* in pod specification. Actions that consume node resources for cpu and memory can be subject to hard quota limits defined by the namespace quota. The resource consumption is measured by resource *request* in pod specification.
Any action that consumes those resources can be tweaked, or can pick up namespace level defaults to meet your end goal. Any action that consumes those resources can be tweaked, or can pick up namespace level defaults to meet your end goal.

View File

@ -275,7 +275,7 @@ We can now build and publish a new container image to the registry with an incre
```shell ```shell
docker build -t gcr.io/PROJECT_ID/hello-node:v2 . docker build -t gcr.io/PROJECT_ID/hello-node:v2 .
docker push gcr.io/PROJECT_ID/hello-node:v2 gcloud docker push gcr.io/PROJECT_ID/hello-node:v2
``` ```
Building and pushing this updated image should be much quicker as we take full advantage of the Docker cache. Building and pushing this updated image should be much quicker as we take full advantage of the Docker cache.

View File

@ -79,7 +79,7 @@ This document is meant to highlight and consolidate in one place configuration b
controller 'version names'. A desired state of an object is described by a Deployment, and if controller 'version names'. A desired state of an object is described by a Deployment, and if
changes to that spec are _applied_, the deployment controller changes the actual state to the changes to that spec are _applied_, the deployment controller changes the actual state to the
desired state at a controlled rate. (Deployment objects are currently part of the [`extensions` desired state at a controlled rate. (Deployment objects are currently part of the [`extensions`
API Group](/docs/api/#api-groups), and are not enabled by default.) API Group](/docs/api/#api-groups).)
- You can manipulate labels for debugging. Because Kubernetes replication controllers and services - You can manipulate labels for debugging. Because Kubernetes replication controllers and services
match to pods using labels, this allows you to remove a pod from being considered by a match to pods using labels, this allows you to remove a pod from being considered by a
@ -108,6 +108,6 @@ This document is meant to highlight and consolidate in one place configuration b
- Use kubectl bulk operations (via files and/or labels) for get and delete. See [label selectors](/docs/user-guide/labels/#label-selectors) and [using labels effectively](/docs/user-guide/managing-deployments/#using-labels-effectively). - Use kubectl bulk operations (via files and/or labels) for get and delete. See [label selectors](/docs/user-guide/labels/#label-selectors) and [using labels effectively](/docs/user-guide/managing-deployments/#using-labels-effectively).
- Use `kubectl run` and `expose` to quickly create and expose single container replication controllers. See the [quick start guide](/docs/user-guide/quick-start/) for an example. - Use `kubectl run` and `expose` to quickly create and expose single container Deployments. See the [quick start guide](/docs/user-guide/quick-start/) for an example.

View File

@ -3,7 +3,7 @@
An issue that comes up rather frequently for new installations of Kubernetes is An issue that comes up rather frequently for new installations of Kubernetes is
that `Services` are not working properly. You've run all your `Pod`s and that `Services` are not working properly. You've run all your `Pod`s and
`ReplicationController`s, but you get no response when you try to access them. `Deployment`s, but you get no response when you try to access them.
This document will hopefully help you to figure out what's going wrong. This document will hopefully help you to figure out what's going wrong.
* TOC * TOC
@ -85,16 +85,15 @@ $ kubectl run hostnames --image=gcr.io/google_containers/serve_hostname \
--labels=app=hostnames \ --labels=app=hostnames \
--port=9376 \ --port=9376 \
--replicas=3 --replicas=3
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS deployment "hostnames" created
hostnames hostnames gcr.io/google_containers/serve_hostname app=hostnames 3
``` ```
Note that this is the same as if you had started the `ReplicationController` with Note that this is the same as if you had started the `Deployment` with
the following YAML: the following YAML:
```yaml ```yaml
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: hostnames name: hostnames
spec: spec:
@ -118,10 +117,10 @@ Confirm your `Pod`s are running:
```shell ```shell
$ kubectl get pods -l app=hostnames $ kubectl get pods -l app=hostnames
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
hostnames-0uton 1/1 Running 0 12s hostnames-632524106-bbpiw 1/1 Running 0 2m
hostnames-bvc05 1/1 Running 0 12s hostnames-632524106-ly40y 1/1 Running 0 2m
hostnames-yp2kp 1/1 Running 0 12s hostnames-632524106-tlaok 1/1 Running 0 2m
``` ```
## Does the Service exist? ## Does the Service exist?
@ -156,7 +155,7 @@ So we have a culprit, let's create the `Service`. As before, this is for the
walk-through - you can use your own `Service`'s details here. walk-through - you can use your own `Service`'s details here.
```shell ```shell
$ kubectl expose rc hostnames --port=80 --target-port=9376 $ kubectl expose deployment hostnames --port=80 --target-port=9376
service "hostnames" exposed service "hostnames" exposed
``` ```
@ -164,8 +163,8 @@ And read it back, just to be sure:
```shell ```shell
$ kubectl get svc hostnames $ kubectl get svc hostnames
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hostnames 10.0.0.1 <none> 80/TCP run=hostnames 1h hostnames 10.0.0.226 <none> 80/TCP 5s
``` ```
As before, this is the same as if you had started the `Service` with YAML: As before, this is the same as if you had started the `Service` with YAML:
@ -580,4 +579,4 @@ Contact us on
## More information ## More information
Visit [troubleshooting document](/docs/troubleshooting/) for more information. Visit [troubleshooting document](/docs/troubleshooting/) for more information.

View File

@ -8,7 +8,7 @@ In this doc, we introduce the Kubernetes command line for interacting with the a
#### docker run #### docker run
How do I run an nginx container and expose it to the world? Checkout [kubectl run](/docs/user-guide/kubectl/kubectl_run). How do I run an nginx Deployment and expose it to the world? Checkout [kubectl run](/docs/user-guide/kubectl/kubectl_run).
With docker: With docker:
@ -25,12 +25,13 @@ With kubectl:
```shell ```shell
# start the pod running nginx # start the pod running nginx
$ kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster" $ kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
replicationcontroller "nginx-app" created deployment "nginx-app" created
# expose a port through with a service # expose a port through with a service
$ kubectl expose rc nginx-app --port=80 --name=nginx-http $ kubectl expose deployment nginx-app --port=80 --name=nginx-http
service "nginx-http" exposed
``` ```
With kubectl, we create a [replication controller](/docs/user-guide/replication-controller) which will make sure that N pods are running nginx (where N is the number of replicas stated in the spec, which defaults to 1). We also create a [service](/docs/user-guide/services) with a selector that matches the replication controller's selector. See the [Quick start](/docs/user-guide/quick-start) for more information. With kubectl, we create a [Deployment](/docs/user-guide/deployments) which will make sure that N pods are running nginx (where N is the number of replicas stated in the spec, which defaults to 1). We also create a [service](/docs/user-guide/services) with a selector that matches the Deployment's selector. See the [Quick start](/docs/user-guide/quick-start) for more information.
By default images are run in the background, similar to `docker run -d ...`, if you want to run things in the foreground, use: By default images are run in the background, similar to `docker run -d ...`, if you want to run things in the foreground, use:
@ -40,8 +41,8 @@ kubectl run [-i] [--tty] --attach <name> --image=<image>
Unlike `docker run ...`, if `--attach` is specified, we attach to `stdin`, `stdout` and `stderr`, there is no ability to control which streams are attached (`docker -a ...`). Unlike `docker run ...`, if `--attach` is specified, we attach to `stdin`, `stdout` and `stderr`, there is no ability to control which streams are attached (`docker -a ...`).
Because we start a replication controller for your container, it will be restarted if you terminate the attached process (e.g. `ctrl-c`), this is different than `docker run -it`. Because we start a Deployment for your container, it will be restarted if you terminate the attached process (e.g. `ctrl-c`), this is different than `docker run -it`.
To destroy the replication controller (and it's pods) you need to run `kubectl delete rc <name>` To destroy the Deployment (and its pods) you need to run `kubectl delete deployment <name>`
#### docker ps #### docker ps
@ -180,20 +181,19 @@ a9ec34d98787
With kubectl: With kubectl:
```shell ```shell
$ kubectl get rc nginx-app $ kubectl get deployment nginx-app
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-app nginx-app nginx run=nginx-app 1 nginx-app 1 1 1 1 2m
$ kubectl get po $ kubectl get po -l run=nginx-app
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
nginx-app-aualv 1/1 Running 0 16s nginx-app-2883164633-aklf7 1/1 Running 0 2m
$ kubectl delete rc nginx-app $ kubectl delete deployment nginx-app
NAME READY STATUS RESTARTS AGE deployment "nginx-app" deleted
nginx-app-aualv 1/1 Running 0 16s $ kubectl get po -l run=nginx-app
$ kubectl get po # Return nothing
NAME READY STATUS RESTARTS AGE
``` ```
Notice that we don't delete the pod directly. With kubectl we want to delete the replication controller that owns the pod. If we delete the pod directly, the replication controller will recreate the pod. Notice that we don't delete the pod directly. With kubectl we want to delete the Deployment that owns the pod. If we delete the pod directly, the Deployment will recreate the pod.
#### docker login #### docker login
@ -263,4 +263,4 @@ KubeUI is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/s
Grafana is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana Grafana is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana
Heapster is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-heapster Heapster is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-heapster
InfluxDB is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb InfluxDB is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb
``` ```

View File

@ -10,13 +10,13 @@ your pods. But there are a number of ways to get even more information about you
## Using `kubectl describe pod` to fetch details about pods ## Using `kubectl describe pod` to fetch details about pods
For this example we'll use a ReplicationController to create two pods, similar to the earlier example. For this example we'll use a Deployment to create two pods, similar to the earlier example.
```yaml ```yaml
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: my-nginx name: nginx-deployment
spec: spec:
replicas: 2 replicas: 2
template: template:
@ -35,53 +35,67 @@ spec:
- containerPort: 80 - containerPort: 80
``` ```
Copy this to a file *./my-nginx-dep.yaml*
```shell ```shell
$ kubectl create -f ./my-nginx-rc.yaml $ kubectl create -f ./my-nginx-dep.yaml
replicationcontrollers/my-nginx deployment "nginx-deployment" created
``` ```
```shell ```shell
$ kubectl get pods $ kubectl get pods
NAME READY REASON RESTARTS AGE NAME READY STATUS RESTARTS AGE
my-nginx-gy1ij 1/1 Running 0 1m nginx-deployment-1006230814-6winp 1/1 Running 0 11s
my-nginx-yv5cn 1/1 Running 0 1m nginx-deployment-1006230814-fmgu3 1/1 Running 0 11s
``` ```
We can retrieve a lot more information about each of these pods using `kubectl describe pod`. For example: We can retrieve a lot more information about each of these pods using `kubectl describe pod`. For example:
```shell ```shell
$ kubectl describe pod my-nginx-gy1ij $ kubectl describe pod nginx-deployment-1006230814-6winp
Name: my-nginx-gy1ij Name: nginx-deployment-1006230814-6winp
Image(s): nginx Namespace: default
Node: kubernetes-node-y3vk/10.240.154.168 Node: kubernetes-node-wul5/10.240.0.9
Labels: app=nginx Start Time: Thu, 24 Mar 2016 01:39:49 +0000
Status: Running Labels: app=nginx,pod-template-hash=1006230814
Reason: Status: Running
Message: IP: 10.244.0.6
IP: 10.244.1.4 Controllers: ReplicaSet/nginx-deployment-1006230814
Replication Controllers: my-nginx (2/2 replicas created)
Containers: Containers:
nginx: nginx:
Image: nginx Container ID: docker://90315cc9f513c724e9957a4788d3e625a078de84750f244a40f97ae355eb1149
Image: nginx
Image ID: docker://6f62f48c4e55d700cf3eb1b5e33fa051802986b77b874cc351cce539e5163707
Port: 80/TCP
QoS Tier:
cpu: Guaranteed
memory: Guaranteed
Limits: Limits:
cpu: 500m cpu: 500m
memory: 128Mi
Requests:
memory: 128Mi memory: 128Mi
cpu: 500m
State: Running State: Running
Started: Thu, 09 Jul 2015 15:33:07 -0700 Started: Thu, 24 Mar 2016 01:39:51 +0000
Ready: True Ready: True
Restart Count: 0 Restart Count: 0
Environment Variables:
Conditions: Conditions:
Type Status Type Status
Ready True Ready True
Volumes:
default-token-4bcbi:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-4bcbi
Events: Events:
FirstSeen LastSeen Count From SubobjectPath Reason Message FirstSeen LastSeen Count From SubobjectPath Type Reason Message
Thu, 09 Jul 2015 15:32:58 -0700 Thu, 09 Jul 2015 15:32:58 -0700 1 {scheduler } scheduled Successfully assigned my-nginx-gy1ij to kubernetes-node-y3vk --------- -------- ----- ---- ------------- -------- ------ -------
Thu, 09 Jul 2015 15:32:58 -0700 Thu, 09 Jul 2015 15:32:58 -0700 1 {kubelet kubernetes-node-y3vk} implicitly required container POD pulled Pod container image "gcr.io/google_containers/pause:0.8.0" already present on machine 54s 54s 1 {default-scheduler } Normal Scheduled Successfully assigned nginx-deployment-1006230814-6winp to kubernetes-node-wul5
Thu, 09 Jul 2015 15:32:58 -0700 Thu, 09 Jul 2015 15:32:58 -0700 1 {kubelet kubernetes-node-y3vk} implicitly required container POD created Created with docker id cd1644065066 54s 54s 1 {kubelet kubernetes-node-wul5} spec.containers{nginx} Normal Pulling pulling image "nginx"
Thu, 09 Jul 2015 15:32:58 -0700 Thu, 09 Jul 2015 15:32:58 -0700 1 {kubelet kubernetes-node-y3vk} implicitly required container POD started Started with docker id cd1644065066 53s 53s 1 {kubelet kubernetes-node-wul5} spec.containers{nginx} Normal Pulled Successfully pulled image "nginx"
Thu, 09 Jul 2015 15:33:06 -0700 Thu, 09 Jul 2015 15:33:06 -0700 1 {kubelet kubernetes-node-y3vk} spec.containers{nginx} pulled Successfully pulled image "nginx" 53s 53s 1 {kubelet kubernetes-node-wul5} spec.containers{nginx} Normal Created Created container with docker id 90315cc9f513
Thu, 09 Jul 2015 15:33:06 -0700 Thu, 09 Jul 2015 15:33:06 -0700 1 {kubelet kubernetes-node-y3vk} spec.containers{nginx} created Created with docker id 56d7a7b14dac 53s 53s 1 {kubelet kubernetes-node-wul5} spec.containers{nginx} Normal Started Started container with docker id 90315cc9f513
Thu, 09 Jul 2015 15:33:07 -0700 Thu, 09 Jul 2015 15:33:07 -0700 1 {kubelet kubernetes-node-y3vk} spec.containers{nginx} started Started with docker id 56d7a7b14dac
``` ```
Here you can see configuration information about the container(s) and Pod (labels, resource requirements, etc.), as well as status information about the container(s) and Pod (state, readiness, restart count, events, etc.) Here you can see configuration information about the container(s) and Pod (labels, resource requirements, etc.), as well as status information about the container(s) and Pod (state, readiness, restart count, events, etc.)
@ -98,48 +112,59 @@ Lastly, you see a log of recent events related to your Pod. The system compresse
## Example: debugging Pending Pods ## Example: debugging Pending Pods
A common scenario that you can detect using events is when you've created a Pod that won't fit on any node. For example, the Pod might request more resources than are free on any node, or it might specify a label selector that doesn't match any nodes. Let's say we created the previous Replication Controller with 5 replicas (instead of 2) and requesting 600 millicores instead of 500, on a four-node cluster where each (virtual) machine has 1 CPU. In that case one of the Pods will not be able to schedule. (Note that because of the cluster addon pods such as fluentd, skydns, etc., that run on each node, if we requested 1000 millicores then none of the Pods would be able to schedule.) A common scenario that you can detect using events is when you've created a Pod that won't fit on any node. For example, the Pod might request more resources than are free on any node, or it might specify a label selector that doesn't match any nodes. Let's say we created the previous Deployment with 5 replicas (instead of 2) and requesting 600 millicores instead of 500, on a four-node cluster where each (virtual) machine has 1 CPU. In that case one of the Pods will not be able to schedule. (Note that because of the cluster addon pods such as fluentd, skydns, etc., that run on each node, if we requested 1000 millicores then none of the Pods would be able to schedule.)
```shell ```shell
$ kubectl get pods $ kubectl get pods
NAME READY REASON RESTARTS AGE NAME READY REASON RESTARTS AGE
my-nginx-9unp9 0/1 Pending 0 8s NAME READY STATUS RESTARTS AGE
my-nginx-b7zs9 0/1 Running 0 8s nginx-deployment-1006230814-6winp 1/1 Running 0 7m
my-nginx-i595c 0/1 Running 0 8s nginx-deployment-1006230814-fmgu3 1/1 Running 0 7m
my-nginx-iichp 0/1 Running 0 8s nginx-deployment-1370807587-6ekbw 1/1 Running 0 1m
my-nginx-tc2j9 0/1 Running 0 8s nginx-deployment-1370807587-fg172 0/1 Pending 0 1m
nginx-deployment-1370807587-fz9sd 0/1 Pending 0 1m
``` ```
To find out why the my-nginx-9unp9 pod is not running, we can use `kubectl describe pod` on the pending Pod and look at its events: To find out why the nginx-deployment-1370807587-fz9sd pod is not running, we can use `kubectl describe pod` on the pending Pod and look at its events:
```shell ```shell
$ kubectl describe pod my-nginx-9unp9 $ kubectl describe pod nginx-deployment-1370807587-fz9sd
Name: my-nginx-9unp9 Name: nginx-deployment-1370807587-fz9sd
Image(s): nginx Namespace: default
Node: / Node: /
Labels: app=nginx Labels: app=nginx,pod-template-hash=1370807587
Status: Pending Status: Pending
Reason: IP:
Message: Controllers: ReplicaSet/nginx-deployment-1370807587
IP: Containers:
Replication Controllers: my-nginx (5/5 replicas created) nginx:
Containers: Image: nginx
nginx: Port: 80/TCP
Image: nginx QoS Tier:
Limits: memory: Guaranteed
cpu: 600m cpu: Guaranteed
memory: 128Mi Limits:
State: Waiting cpu: 1
Ready: False memory: 128Mi
Restart Count: 0 Requests:
Events: cpu: 1
FirstSeen LastSeen Count From SubobjectPath Reason Message memory: 128Mi
Thu, 09 Jul 2015 23:56:21 -0700 Fri, 10 Jul 2015 00:01:30 -0700 21 {scheduler } failedScheduling Failed for reason PodFitsResources and possibly others Environment Variables:
Volumes:
default-token-4bcbi:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-4bcbi
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1m 48s 7 {default-scheduler } Warning FailedScheduling pod (nginx-deployment-1370807587-fz9sd) failed to fit in any node
fit failure on node (kubernetes-node-6ta5): Node didn't have enough resource: CPU, requested: 1000, used: 1420, capacity: 2000
fit failure on node (kubernetes-node-wul5): Node didn't have enough resource: CPU, requested: 1000, used: 1100, capacity: 2000
``` ```
Here you can see the event generated by the scheduler saying that the Pod failed to schedule for reason `PodFitsResources` (and possibly others). `PodFitsResources` means there were not enough resources for the Pod on any of the nodes. Due to the way the event is generated, there may be other reasons as well, hence "and possibly others." Here you can see the event generated by the scheduler saying that the Pod failed to schedule for reason `FailedScheduling` (and possibly others). The message tells us that there were not enough resources for the Pod on any of the nodes.
To correct this situation, you can use `kubectl scale` to update your Replication Controller to specify four or fewer replicas. (Or you could just leave the one Pod pending, which is harmless.) To correct this situation, you can use `kubectl scale` to update your Deployment to specify four or fewer replicas. (Or you could just leave the one Pod pending, which is harmless.)
Events such as the ones you saw at the end of `kubectl describe pod` are persisted in etcd and provide high-level information on what is happening in the cluster. To list all events you can use Events such as the ones you saw at the end of `kubectl describe pod` are persisted in etcd and provide high-level information on what is happening in the cluster. To list all events you can use
@ -158,65 +183,75 @@ To see events from all namespaces, you can use the `--all-namespaces` argument.
In addition to `kubectl describe pod`, another way to get extra information about a pod (beyond what is provided by `kubectl get pod`) is to pass the `-o yaml` output format flag to `kubectl get pod`. This will give you, in YAML format, even more information than `kubectl describe pod`--essentially all of the information the system has about the Pod. Here you will see things like annotations (which are key-value metadata without the label restrictions, that is used internally by Kubernetes system components), restart policy, ports, and volumes. In addition to `kubectl describe pod`, another way to get extra information about a pod (beyond what is provided by `kubectl get pod`) is to pass the `-o yaml` output format flag to `kubectl get pod`. This will give you, in YAML format, even more information than `kubectl describe pod`--essentially all of the information the system has about the Pod. Here you will see things like annotations (which are key-value metadata without the label restrictions, that is used internally by Kubernetes system components), restart policy, ports, and volumes.
```yaml ```yaml
$ kubectl get pod my-nginx-i595c -o yaml $kubectl get pod nginx-deployment-1006230814-6winp -o yaml
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
annotations: annotations:
kubernetes.io/created-by: '{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationController","namespace":"default","name":"my-nginx","uid":"c555c14f-26d0-11e5-99cb-42010af00e4b","apiVersion":"v1","resourceVersion":"26174"}}' kubernetes.io/created-by: |
creationTimestamp: 2015-07-10T06:56:21Z {"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-deployment-1006230814","uid":"4c84c175-f161-11e5-9a78-42010af00005","apiVersion":"extensions","resourceVersion":"133434"}}
generateName: my-nginx- creationTimestamp: 2016-03-24T01:39:50Z
generateName: nginx-deployment-1006230814-
labels: labels:
app: nginx app: nginx
name: my-nginx-i595c pod-template-hash: "1006230814"
name: nginx-deployment-1006230814-6winp
namespace: default namespace: default
resourceVersion: "26243" resourceVersion: "133447"
selfLink: /api/v1/namespaces/default/pods/my-nginx-i595c selfLink: /api/v1/namespaces/default/pods/nginx-deployment-1006230814-6winp
uid: c558e44b-26d0-11e5-99cb-42010af00e4b uid: 4c879808-f161-11e5-9a78-42010af00005
spec: spec:
containers: containers:
- image: nginx - image: nginx
imagePullPolicy: IfNotPresent imagePullPolicy: Always
name: nginx name: nginx
ports: ports:
- containerPort: 80 - containerPort: 80
protocol: TCP protocol: TCP
resources: resources:
limits: limits:
cpu: 600m cpu: 500m
memory: 128Mi
requests:
cpu: 500m
memory: 128Mi memory: 128Mi
terminationMessagePath: /dev/termination-log terminationMessagePath: /dev/termination-log
volumeMounts: volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-zkhkk name: default-token-4bcbi
readOnly: true readOnly: true
dnsPolicy: ClusterFirst dnsPolicy: ClusterFirst
nodeName: kubernetes-node-u619 nodeName: kubernetes-node-wul5
restartPolicy: Always restartPolicy: Always
securityContext: {}
serviceAccount: default
serviceAccountName: default serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes: volumes:
- name: default-token-zkhkk - name: default-token-4bcbi
secret: secret:
secretName: default-token-zkhkk secretName: default-token-4bcbi
status: status:
conditions: conditions:
- status: "True" - lastProbeTime: null
lastTransitionTime: 2016-03-24T01:39:51Z
status: "True"
type: Ready type: Ready
containerStatuses: containerStatuses:
- containerID: docker://9506ace0eb91fbc31aef1d249e0d1d6d6ef5ebafc60424319aad5b12e3a4e6a9 - containerID: docker://90315cc9f513c724e9957a4788d3e625a078de84750f244a40f97ae355eb1149
image: nginx image: nginx
imageID: docker://319d2015d149943ff4d2a20ddea7d7e5ce06a64bbab1792334c0d3273bbbff1e imageID: docker://6f62f48c4e55d700cf3eb1b5e33fa051802986b77b874cc351cce539e5163707
lastState: {} lastState: {}
name: nginx name: nginx
ready: true ready: true
restartCount: 0 restartCount: 0
state: state:
running: running:
startedAt: 2015-07-10T06:56:28Z startedAt: 2016-03-24T01:39:51Z
hostIP: 10.240.112.234 hostIP: 10.240.0.9
phase: Running phase: Running
podIP: 10.244.3.4 podIP: 10.244.0.6
startTime: 2015-07-10T06:56:21Z startTime: 2016-03-24T01:39:49Z
``` ```
## Example: debugging a down/unreachable node ## Example: debugging a down/unreachable node

View File

@ -14,11 +14,11 @@ as storage volumes and IP addresses.
Single-container pods can be created with the `run` command. The Single-container pods can be created with the `run` command. The
pod's properties are specified with flags on the command line. pod's properties are specified with flags on the command line.
The `run` command creates a replication controller to monitor the pod(s). The `run` command creates a Deployment to monitor the pod(s).
The controller watches for failed pods and will start up new pods as required The Deployment watches for failed pods and will start up new pods as required
to maintain the specified number. to maintain the specified number.
Note: If you don't want a replication controller to monitor your pod (e.g. your pod Note: If you don't want a Deployment to monitor your pod (e.g. your pod
is writing non-persistent data which won't survive a restart, or your pod is is writing non-persistent data which won't survive a restart, or your pod is
intended to be very short-lived), you can intended to be very short-lived), you can
[create a pod directly with the `create` command](/docs/user-guide/pods/multi-container/). [create a pod directly with the `create` command](/docs/user-guide/pods/multi-container/).
@ -36,16 +36,16 @@ $ kubectl run NAME
Where: Where:
* `NAME` (required) is the name of the container to create. This value is also * `NAME` (required) is the name of the container to create. This value is also
applied as the name of the replication controller, and as the prefix of the applied as the name of the Deployment, and as the prefix of the
pod name. For example: pod name. For example:
```shell ```shell
$ kubectl run example --image=nginx $ kubectl run example --image=nginx
replicationcontroller "example" created deployment "example" created
$ kubectl get pods $ kubectl get pods -l run=example
NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE
example-xypvc 1/1 Running 0 13s example-1934187764-scau1 1/1 Running 0 13s
``` ```
* `--image=IMAGE` (required) is the Docker container image to use for this * `--image=IMAGE` (required) is the Docker container image to use for this
container. container.
@ -54,7 +54,7 @@ Where:
one pod will be created. one pod will be created.
* `--labels=key=value` specifies one or more labels to attach to the pod. In * `--labels=key=value` specifies one or more labels to attach to the pod. In
addition to any labels specified here, `run` attaches a label of addition to any labels specified here, `run` attaches a label of
the format `run=NAME`. This is used by the replication controller the format `run=NAME`. This is used by the Deployment
to target the pods created by the command. to target the pods created by the command.
There are additional flags that can be specified. For a complete list, run: There are additional flags that can be specified. For a complete list, run:
@ -68,21 +68,21 @@ There are additional flags that can be specified. For a complete list, run:
## Deleting a pod ## Deleting a pod
If your pod was created using the `run` command, kubernetes creates a If your pod was created using the `run` command, kubernetes creates a
[replication controller](/docs/user-guide/replication-controller/) [Deployment](/docs/user-guide/deployments/)
to manage the pod. Pods managed by a replication controller are rescheduled if to manage the pod. Pods managed by a Deployment are rescheduled if
they go away, including being deleted by `kubectl delete pod`. To permanently they go away, including being deleted by `kubectl delete pod`. To permanently
delete the pod, delete its replication controller. delete the pod, delete its Deployment.
First, find the controller's name: First, find the Deployment's name:
```shell ```shell
$ kubectl get rc $ kubectl get deployment
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
example example busybox run=example 1 example 1 1 1 1 1m
``` ```
Then, `delete` the controller: Then, `delete` the Deployment:
```shell ```shell
$ kubectl delete rc CONTROLLER_NAME $ kubectl delete deployment DEPLOYMENT_NAME
``` ```

2
images/nav_logo.svg Executable file → Normal file

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

2
images/nav_logo2.svg Executable file → Normal file

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB