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.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Step 1: Set Up the Deployment Directory
First, navigate to your project directory and create a new folder calleddeployments. Inside this folder, create a file named deployment.yaml.
Step 2: Review the ReplicaSet Definition
For reference, open the existing ReplicaSet definition on the right side of your split editor:Review this ReplicaSet definition carefully, as you will reuse its structure when defining your new deployment.
Step 3: Create the Deployment Configuration
In your newdeployment.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:
The deployment uses the same selector as the ReplicaSet, matching on
app: myapp. This ensures that the deployment’s pods are correctly managed.Step 4: Reference the Original ReplicaSet Definition
For comparison, here is the unchanged ReplicaSet definition saved inreplicaset.yaml:
Step 5: Deploy the Configuration to Your Cluster
Save your deployment configuration and create the deployment by running the following command in your terminal:Step 6: Validate the Pods
To inspect the pods created by the deployment, execute:app: myapp), ensuring three desired and three available pods are running.
Step 7: Review All Cluster Objects
Finally, run the following command to list all objects created in the cluster: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.