Sunday, August 13, 2023

What is Kubernetes Deployment YAML

A Kubernetes user or administrator specifies data in a YAML file, typically to define a Kubernetes object. The YAML configuration is called a “manifest”, and when it is “applied” to a Kubernetes cluster, Kubernetes creates an object based on the configuration.


A Kubernetes Deployment YAML specifies the configuration for a Deployment object—this is a Kubernetes object that can create and update a set of identical pods. Each pod runs specific containers, which are defined in the spec.template field of the YAML configuration. 


The Deployment object not only creates the pods but also ensures the correct number of pods is always running in the cluster, handles scalability, and takes care of updates to the pods on an ongoing basis. All these activities can be configured through fields in the Deployment YAML. 


The following YAML configuration creates a Deployment object that runs 5 replicas of an NGINX container.


apiVersion: apps/v1

kind: Deployment

metadata:

  name: nginx-deployment

  labels:

    app: web

spec:

  selector:

    matchLabels:

      app: web

  replicas: 5

  strategy:

    type: RollingUpdate

  template:

    metadata:

      labels:

        app: web

    spec:

      containers:

       —name: nginx

          image: nginx

          ports:

           —containerPort: 80



spec.replicas—specifies how many pods to run

strategy.type—specifies which deployment strategy should be used. In this case and in the following examples we select RollingUpdate, which means new versions are rolled out gradually to pods to avoid downtime.

spec.template.spec.containers—specifies which container image to run in each of the pods and ports to expose.



Below is how to specify the limits 


 spec:

      containers:

       —name: nginx

          image: nginx

          resources:

            limits:

              memory: 200Mi

            requests:

              cpu: 100m

              memory: 200Mi

          ports:

           —containerPort: 80



limits—each container should not be allowed to consume more than 200Mi of memory.

requests—each container requires 100m of CPU resources and 200Mi of memory on the node



references:

https://codefresh.io/learn/kubernetes-deployment/kubernetes-deployment-yaml/#:~:text=The%20Deployment%20object%20not%20only,fields%20in%20the%20Deployment%20YAML.


No comments:

Post a Comment