Hello, readers! In this article, we will be focusing on Kubernetes Deployment in detail. So, let us begin!! 🙂
What are Workloads in Kubernetes?
Kubernetes provides us with workloads to hold our application-level data and configuration. Workloads are the applications running on Kubernetes through Pods packaged inside the containers.
There are various built-in k8 workload resources as shown below:
- Deployment: This resource describes the desired state of the application. The Deployment Controller converts the current/actual state of the application to the mentioned desired state of the application at a controlled and managed rate.
- ReplicaSet: It describes and maintains the stable set of pods to hold the workloads in the containers by creating replicas of the workloads at that time.
- StatefulSet: It helps in managing the stateful applications over the workloads. it maintains the Pods that are related and somehow tracks the state of the application. They even manage the deployment and scaling of a set of Pods.
- Job: These resources define a set of tasks that run until they get completed and then abort the process and stops.
- CronJob: These resources define the set of Jobs that are scheduled to be executed over a certain period of time.
Kubernetes Deployment Template
Now, let us have a look at the deployment resource template that would include the deployment of the workload for the pods to act on in the cluster.
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world-app labels: app: app spec: replicas: 2 selector: matchLabels: app: app template: metadata: labels: app: app spec: containers: - name: hello-world image: hello-world:1.0 ports: - containerPort: 80
- The .metadata.name filed: It describes the name of the Deployment to be created.
- The .spec.replicas filed: It describes the number of replicas of the pods to be created. In our case, we have created 2 replicas.
- The .spec.selector field: This field defines which pods need to be managed by the Deployment. In this case, we match the label ‘app’ with the label ‘app’ in the Pod template and this is how the deployment decides which Pods needs to be orchestrated by it.
- The .spec.containers field: This field describes the information about the container such as container name, image name, and containerPort values which define the port on which the deployed application would be available outside the boundary of the container.
5 kubectl commands with respect to k8 Deployments
- Creation of a Deployment:
kubectl apply -f deployment.yaml
2. Check for the presence of deployment applied above:
kubectl get deployments
3. Get the list of replica sets created by the deployment:
kubectl get rs
4. Update the image in a deployment:
kubectl set image deployment/deployment-name new-image-name --record
5. Get the details of the deployment:
kubectl describe deployments
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any questions. For more such posts related to Kubernetes, Stay tuned with us!
Till then, Happy Learning!! 🙂