This lesson covers creating a Kubernetes deployment using an existing ReplicaSet definition to streamline the process.
In this lesson, we will create a Kubernetes deployment by leveraging an existing ReplicaSet definition. This approach helps streamline the process by reusing a familiar structure.
In your new deployment.yaml file, start with the apiVersion (apps/v1) as used in the ReplicaSet. Set the kind to Deployment, and then define the metadata with a unique name and appropriate labels. In our example, we use the name myapp-deployment with labels like tier: frontend and app: nginx.For the spec section, copy the structure from the ReplicaSet but modify the configuration to meet the deployment requirements. In this case, we reduce the number of replicas from four to three.Below is the final configuration for your deployment:
To inspect the pods created by the deployment, execute:
Copy
Ask AI
kubectl get pods
Expected output:
Copy
Ask AI
NAME READY STATUS RESTARTS AGEmyapp-replicaset-pjs89 1/1 Running 0 34mmyapp-replicaset-pwv6h 1/1 Running 0 34mmyapp-replicaset-zr6c7 1/1 Running 0 23s
For more detailed information about your deployment, use:
Copy
Ask AI
kubectl describe deployment myapp-deployment
This command provides comprehensive details on metadata, pod specifications, and events. You will see that the deployment uses the same selector (app: myapp), ensuring three desired and three available pods are running.
Finally, run the following command to list all objects created in the cluster:
Copy
Ask AI
kubectl get all
A sample output might look like this:
Copy
Ask AI
NAME READY STATUS RESTARTS AGEpod/myapp-replicaset-pjs89 1/1 Running 0 35mpod/myapp-replicaset-pwv6h 1/1 Running 0 35mpod/myapp-replicaset-zr6c7 1/1 Running 0 104sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 65mNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/myapp-deployment 3/3 3 3 105sNAME DESIRED CURRENT READY AGEreplicaset.apps/myapp-replicaset 3 3 3 35m
This output confirms that both the deployment and its corresponding ReplicaSet have been successfully created, with the expected pods up and running.
You have now successfully deployed your application using Kubernetes Deployments. Experiment with these configurations in your practice environment for a deeper understanding of Kubernetes object management.