Deployment use cases

We'll explore a number of typical scenarios for deployments in more detail:

  • Roll out a ReplicaSet
  • Update the state of a set of Pods
  • Roll back to an earlier version of a Deployment
  • Scale up to accommodate cluster load
  • Pause and use Deployment status in order to make changes or indicate a stuck deployment
  • Clean up a deployment

In the following code of the node-js-deploy.yaml file, we can see that the definition is very similar to a ReplicationController. The main difference is that we now have an ability to make changes and updates to the deployment objects and let Kubernetes manage updating the underlying pods and replicas for us:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: node-js-deploy
labels:
name: node-js-deploy
spec:
replicas: 1
template:
metadata:
labels:
name: node-js-deploy
spec:
containers:
- name: node-js-deploy
image: jonbaier/pod-scaling:0.1
ports:
- containerPort: 80

In this example, we've created a Deployment named node-js-deploy via the name field under metadata. We're creating a single pod that will be managed by the selector field, which is going to help the Deployment understand which pods to manage. The spec tells the pod to run the jobbaier/pod-scaling container and directs traffic through port 80 via the containerPort.

We can run the familiar create command with the optional --record flag so that the creation of the Deployment is recorded in the rollout history. Otherwise, we will only see subsequent changes in the rollout history using the $ kubectl create -f node-js-deploy.yaml --record command.

You may need to add --validate=false if this beta type is not enabled on your cluster.

We should see a message about the deployment being successfully created. After a few moments, it will finish creating our pod, which we can check for ourselves with a get pods command. We add the -l flag to only see the pods relevant to this deployment:

$ kubectl get pods -l name=node-js-deploy

If you'd like to get the state of the deployment, you can issue the following:

$ kubectl get deployments

You can also see the state of a rollout, which will be more useful in the future when we update our Deployments. You can use kubectl rollout status deployment/node-js-deploy to see what's going on.

We create a service just as we did with ReplicationControllers. The following is a Service definition for the Deployment we just created. Notice that it is almost identical to the Services we created in the past. Save the following code in node-js-deploy-service.yaml file:

apiVersion: v1
kind: Service
metadata:
name: node-js-deploy
labels:
name: node-js-deploy
spec:
type: LoadBalancer
ports:
- port: 80
sessionAffinity: ClientIP
selector:
name: node-js-deploy

Once this service is created using kubectl, you'll be able to access the deployment pods through the service IP or the service name if you are inside a pod on this namespace. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.10.201