Deploying Applications with kubectl Tutorial


kubectl is a command-line tool that allows you to interact with and manage Kubernetes clusters. In Azure Kubernetes Service (AKS), kubectl is used to deploy applications, manage resources, and perform various operations on your Kubernetes cluster. This tutorial will guide you through the process of deploying applications using kubectl in AKS.

Step 1: Connect to the AKS Cluster

Before deploying applications, you need to connect to your AKS cluster using kubectl. Run the following command to authenticate and set the context for your cluster:

az aks get-credentials --resource-group --name

Step 2: Create a Deployment

The next step is to create a Deployment object, which defines the desired state of your application. The Deployment includes specifications such as the container image, number of replicas, and resource requirements. Here's an example of a Deployment manifest:

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

Common Mistakes to Avoid

  • Using incorrect API versions or resource kinds in the manifest files.
  • Not specifying the correct image name or tag in the Deployment manifest.
  • Missing or incorrect labels and selectors, leading to issues with resource associations.
  • Not properly defining resource requirements, which can impact application performance and scalability.

Frequently Asked Questions (FAQs)

  1. What is kubectl?

    kubectl is a command-line tool used to interact with Kubernetes clusters. It enables you to manage and deploy applications, view cluster information, and perform various operations.

  2. How do I install kubectl?

    You can install kubectl by following the official documentation for your operating system. It is available for Windows, macOS, and Linux.

  3. How do I deploy an application with kubectl?

    You can deploy an application using kubectl by creating a Deployment manifest file and applying it to your AKS cluster with the command `kubectl apply -f deployment.yaml`.

  4. How can I scale my application using kubectl?

    You can scale your application by modifying the `replicas` field in the Deployment manifest and applying the changes with `kubectl apply -f deployment.yaml`.

  5. Can I roll back a deployment with kubectl?

    Yes, you can roll back a deployment to a previous revision by using the `kubectl rollout undo` command. It allows you to revert to a known stable state.


Deploying applications with kubectl in Azure Kubernetes Service (AKS) is a straightforward process. By connecting to your AKS cluster and creating a Deployment manifest, you can define the desired state of your application and easily deploy it to your cluster. Avoid common mistakes such as using incorrect API versions or resource kinds, specifying the wrong image names or tags, and not properly defining labels and resource requirements. With kubectl, you have the power to manage and deploy your applications efficiently in AKS.