Deployments are a fundamental and powerful pattern in Kubernetes. In this post, I show you how to get started with Deployments very quickly and easily!
Deployments are a type of Controller. A Controller is a declarative pattern that ensures the state you have configured for your Kubernetes cluster is provisioned.
Let us recap some basics: Kubernetes, fundamentally, is a container orchestration system. Containers run your applications. In the context of Kubernetes, Pods are what containers run in. Pods can be created on their own or through a Controller such as a ReplicaSet. If you are provisioning a Pod, it is recommended, in most cases, to provision it through a ReplicaSet.
This is where Deployments come in.
Deployments manage ReplicaSets. It is best practice to not create ReplicaSets (unless you need to – more on that later) but use Deployments.
Deployments are used for:
- Deploying a ReplicaSet
- Deploy a new, updated version or state of an existing ReplicaSet (for example a ReplicaSet which has a Pod Template pointing to a new version of the Container Images)
- Rollingback to an earlier version of a ReplicaSet
- Do various housekeeping tasks such as cleanup etc
Kubernetes Deployment Tutorial
Here is a quick and easy way to get familiar with Deployments on your own Cluster.
I am using Kubernetes Kind but you can use Minikube or any other setup you have.
Kubernetes Deployment YAML Example
Here is what a basic deployment manifest looks like:
apiVersion: apps/v1 kind: Deployment metadata: name: gohello-deployment labels: app: gohello tier: frontend spec: replicas: 3 selector: matchLabels: app: gohello-app template: metadata: labels: app: gohello-app spec: containers: - name: gohello image: vgoel/gohello ports: - containerPort: 8080
Save the above piece of code in a filed named gohello-deployment.yaml and then run this command:
kubectl create -f gohello-deployment.yaml
If all went well, you should see your Pods running: