Step 1: Set Up Your Project Directory
Create a new folder calledDeployments within your project directory. Then, inside the Deployments folder, create a file named deployment.yaml.
Using a split editor can help you compare the new deployment file with your existing ReplicaSet definition side by side.
Step 2: Base Your Deployment on the ReplicaSet Definition
Locate your existingReplicaSet.yaml file and open it in a split view with your new deployment.yaml file. This approach lets you reference the ReplicaSet configuration while you build your Deployment.
Begin your deployment.yaml file by specifying the API version and kind. Since the ReplicaSet uses apps/v1, you will use the same API version, but change the kind to Deployment:
Step 3: Define Metadata
Next, add metadata details for your deployment. For example, set the deployment name tomyapp-deployment and include labels to help categorize and identify the deployment:
Step 4: Configure the Spec Section
The specification section of the deployment is very similar to the ReplicaSet’s. You can copy the spec section fromReplicaSet.yaml and modify it as necessary. In this example, update the replica count to three:
ReplicaSet.yaml content that served as a starting point:
Step 5: Deploy Your Configuration
After saving your changes todeployment.yaml, open your terminal, navigate to the project’s root directory, and confirm that the Deployments directory exists.
To create the deployment, run the following command using kubectl with the -f flag to specify your deployment file:
Step 6: Verify the Pods and Deployment Details
To view the Pods created by the ReplicaSet for this deployment, execute:Step 7: List All Kubernetes Objects
To view all objects created in your cluster, run the following command:myapp-replicaset), and the three Pods managed by the ReplicaSet.
This lesson has guided you through creating a Kubernetes Deployment from a ReplicaSet template, deploying it using
kubectl, and verifying the deployment along with its associated Pods.