0
0
Kubernetesdevops~30 mins

Creating Deployments with YAML in Kubernetes - Try It Yourself

Choose your learning style9 modes available
Creating Deployments with YAML
📖 Scenario: You are working as a DevOps engineer. Your team needs to deploy a simple web application on Kubernetes. You will create a Deployment YAML file step-by-step to manage the application pods.
🎯 Goal: Build a Kubernetes Deployment YAML file that defines a Deployment named webapp-deployment running 3 replicas of the nginx:1.21 container.
📋 What You'll Learn
Create a Deployment YAML with apiVersion, kind, and metadata
Add a spec section with replicas and selector
Define the pod template with container name and image
Output the complete YAML content
💡 Why This Matters
🌍 Real World
Kubernetes Deployments are used to manage and scale containerized applications in production environments.
💼 Career
Understanding how to write Deployment YAML files is essential for DevOps engineers and site reliability engineers working with Kubernetes.
Progress0 / 4 steps
1
Create the Deployment header and metadata
Create a YAML file starting with apiVersion: apps/v1, kind: Deployment, and metadata with name: webapp-deployment.
Kubernetes
Need a hint?

Start by specifying the API version, the kind of resource, and the deployment name under metadata.

2
Add replicas and selector to the spec
Add a spec section with replicas: 3 and a selector matching app: webapp under matchLabels.
Kubernetes
Need a hint?

The spec defines how many pods to run and how to select them using labels.

3
Define the pod template with container details
Under spec.template, add metadata.labels with app: webapp. Then add spec.containers with one container named nginx-container using the image nginx:1.21.
Kubernetes
Need a hint?

The pod template defines the pods that will be created. Labels must match the selector. Containers need a name and image.

4
Output the complete Deployment YAML
Print the entire YAML content stored in a variable called deployment_yaml.
Kubernetes
Need a hint?

Use print(deployment_yaml) to show the full YAML content.