![Kubernetes Deployment YAML File with Example](https://assets.community.aws/a/2caY3iEtqpnUqDZwBKXlwnN96OO/Kube.webp)
Kubernetes Deployment YAML File with Example
Learn how to create a Kubernetes Deployment with Example
Published Feb 19, 2024
In this article, we will take a look at the anatomy of the Kubernetes deployment YAML file also known as configuration files or manifests. We will explain what a deployment is in Kubernetes and how you would use a deployment YAML file with a useful example.
We will cover:
- What is a Kubernetes Deployment?
- How do I create a YAML file for Kubernetes deployment?
- Kubernetes deployment YAML – Example
1- What is a Kubernetes Deployment?
Kubernetes Deployment is the process of providing declarative updates to Pods and ReplicaSets, It allows users to declare the desired state in the manifest (YAML), and the controller will change the current state to the declared state.
2- How do I create a YAML file for Kubernetes deployment?
Like any other Kubernetes configuration, a deployment file will contain the following:
- apiVersion represents the version of the Kubernetes API used to create this object
- Kind represents the type of Kubernetes objects to be created while using the YAML file
- The metadata with a spec section to define the replicas and configurations related to the deployment
- The replicas define the number of pods
- The selector in which the controller will select the targeted pods.
- The template section contains the actual template for the pod
- The containers section defines the container details such as:
- Docker image label
- The container port
- Environment variables used in that service with their specific value
- The **envFrom** defines all of the secrets data as container environment variables.
- We are referring to the Secrets in that service using envFrom.secretRef
- The key from the secrets.yml becomes the environment variable name in the Pod.
We can create the deployment using the following command: kubectl apply -f <deployment file path>
3-Kubernetes deployment YAML – Example:
The example below will create a Kubernetes Deployment named “car-service” for the develop environment with one replica, running a pod based on the specified container image and port configuration.
![Deployment YAML File Deployment YAML File](https://assets.community.aws/a/2caWyjRqSlN5Q3sKCF5yTBOPvP6/Scre.webp)