This page shows how to run an application using a Kubernetes Deployment object.
You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using Minikube.
You can run an application by creating a Kubernetes Deployment object, and you can describe a Deployment in a YAML file. For example, this YAML file describes a Deployment that runs the nginx:1.7.9 Docker image:
Create a Deployment based on the YAML file:
export REPO=https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master kubectl create -f $REPO/docs/tutorials/stateless-application/deployment.yaml
Display information about the Deployment:
kubectl describe deployment nginx-deployment user@computer:~/kubernetes.github.io$ kubectl describe deployment nginx-deployment Name: nginx-deployment Namespace: default CreationTimestamp: Tue, 30 Aug 2016 18:11:37 -0700 Labels: app=nginx Selector: app=nginx Replicas: 2 updated | 2 total | 2 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 1 max unavailable, 1 max surge OldReplicaSets: <none> NewReplicaSet: nginx-deployment-1771418926 (2/2 replicas created) No events.
List the pods created by the deployment:
kubectl get pods -l app=nginx NAME READY STATUS RESTARTS AGE nginx-deployment-1771418926-7o5ns 1/1 Running 0 16h nginx-deployment-1771418926-r18az 1/1 Running 0 16h
Display information about a pod:
kubectl describe pod <pod-name>
<pod-name> is the name of one of your pods.
You can update the deployment by applying a new YAML file. This YAML file specifies that the deployment should be updated to use nginx 1.8.
Apply the new YAML file:
kubectl apply -f $REPO/docs/tutorials/stateless-application/deployment-update.yaml
Watch the deployment create pods with new names and delete the old pods:
kubectl get pods -l app=nginx
You can increase the number of pods in your Deployment by applying a new YAML
file. This YAML file sets
replicas to 4, which specifies that the Deployment
should have four pods:
Apply the new YAML file:
kubectl apply -f $REPO/docs/tutorials/stateless-application/deployment-scale.yaml
Verify that the Deployment has four pods:
kubectl get pods
The output is similar to this:
NAME READY STATUS RESTARTS AGE nginx-deployment-148880595-4zdqq 1/1 Running 0 25s nginx-deployment-148880595-6zgi1 1/1 Running 0 25s nginx-deployment-148880595-fxcez 1/1 Running 0 2m nginx-deployment-148880595-rwovn 1/1 Running 0 2m
Delete the deployment by name:
kubectl delete deployment nginx-deployment