You are currently viewing Kubernetes Deployment Manifest File in YAML

Kubernetes Deployment Manifest File in YAML

Introduction:

In this guide, we’ll delve into Kubernetes Deployment Manifest File in YAML, a vital aspect of Kubernetes configuration. Kubernetes Deployment Manifest File in YAML simplifies resource definition and application management on your cluster. Follow along as we explore the creation of Deployment Manifest Files, complete with illustrative examples and key insights for effective Kubernetes deployment management.

1. Understanding the Basics

Before we dive into creating a Deployment Manifest File, let’s understand the basic structure and components:

  • apiVersion: Specifies the Kubernetes API version being used.
  • kind: Defines the type of resource (e.g., Deployment).
  • metadata: Contains metadata like the name and labels.
  • spec: Describes the desired state of the resource.

2. Creating a Simple Deployment

Here’s a minimal example of a Deployment YAML file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: sample-container
        image: nginx:latest
        ports:
        - containerPort: 80

Explanation:

  • apiVersion: We’re using the apps/v1 API version.
  • kind: This is a Deployment resource.
  • metadata: Specifies the name of the deployment.
  • spec: Describes the desired state.
  • replicas: Sets the desired number of replicas (pods).
  • selector: Defines how to select the pods managed by this deployment.
  • template: Describes the pod template.
    • metadata: Labels for the pods.
    • spec: Defines the container(s) within the pod.

3. Deploying the YAML File

Save the YAML file (e.g., deployment.yaml) and apply it to your Kubernetes cluster using the following command:

kubectl apply -f deployment.yaml

4. Scaling the Deployment

You can scale the deployment by updating the replicas field in the Deployment Manifest File and applying the changes again.

spec:
  replicas: 5

Apply the changes:

kubectl apply -f deployment.yaml

5. Rolling Updates and Rollbacks

To perform a rolling update, change the container image in the Deployment Manifest File and apply the changes:

spec:
  template:
    spec:
      containers:
      - name: sample-container
        image: nginx:1.19.10

Apply the changes:

kubectl apply -f deployment.yaml

To roll back to a previous version:

kubectl rollout undo deployment sample-deployment

Conclusion

Creating and managing a Deployment in Kubernetes using a YAML file provides a declarative way to define and control your application’s lifecycle. This tutorial covered the basics, scaling, rolling updates, and rollbacks. Customize the YAML file based on your application’s requirements for a seamless Kubernetes deployment experience.

This Post Has 2 Comments

  1. googletest

    I am sure this post has touched all the internet viewers,
    its really really fastidious paragraph on building
    up new blog.

  2. playoffs

    Its not my first time to visit this web page, i am browsing
    this site dailly and obtain nice information from here
    everyday.

Leave a Reply