Create, Update and Delete Deployments With Kubectl on Kubernetes AKS

This blog post will show you how to create, update, and delete deployments on Kubernetes AKS cluster with kubectl.

It is important to note that in my case, I am using an Azure AKS cluster, but the below commands will work with any Kubernetes cluster either on AWS, OCI or GCP.


In the below deployment I have an Nginx replicaset with 2 pods.

apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
    app: nginx
  replicas: 2
      app: nginx
        app: nginx
      - name: nginx
        image: nginx:latest
        - containerPort: 80

To create the deployment, I will save the above file as deploy. yaml inside a directory and create the deployment with the following command:

kubectl apply -f deploy.yaml

After the command is finished, the deployment is ready and up. To check the status, I will run the following command.

kubectl get deployments.apps

Update Deployment

If needed, I can update the deployment by editing the deploy.yaml file and change the number of replicas. The update command is the same as the create command, and it will look as shown below.

kubectl apply -f deploy.yaml

If nothing has changed, nothing will happed to the deployment.

Delete a Deployment

The final step is to delete the deployment. When running all the objects that belong to the deployment will get deleted immediately. The command below will delete the deployment.

kubectl delete -f deploy.yaml 

Success! You're on the list.