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.

Deployment

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

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - 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 

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.