Category

azure

Kubernetes on Azure: Setting up a cluster on Microsoft Azure (with Azure AKS)

Kubernetes on Azure: Setting up a cluster on Microsoft Azure (with Azure AKS)

Prerequisites

  • A Microsoft Azure account with administrative access
  • A basic understanding of Kubernetes concepts
  • A local machine with the az and kubectl command-line tools installed

Step 1: Create an Azure Kubernetes Service Cluster

  • Open the Azure portal and navigate to the AKS console.
  • Click on “Add” to create a new AKS cluster.
  • Choose a name for your cluster and select the region and resource group where you want to create it.
  • Choose the number and type of nodes you want to create in your cluster.
  • Choose the networking options for your cluster.
  • Review your settings and click on “Create”.

Step 2: Configure kubectl

  • Install the az CLI tool if you haven’t already done so.
  • Run the following command to authenticate kubectl with your Azure account:
  • az login
  • This command opens a web page and asks you to log in to your Azure account.
  • Run the following command to configure kubectl to use your AKS cluster:
  • az aks get-credentials --name myAKSCluster --resource-group myResourceGroup
  • Replace myAKSCluster with the name of your AKS cluster, and myResourceGroup with the name of the resource group where your cluster is located.
  • This command updates your kubectl configuration to use the Azure account that you used to create your cluster. It also sets the current context to your AKS cluster.

Step 3: Verify Your Cluster

kubectl get nodes

Step 4: Deploy Applications to Your Cluster

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
  type: LoadBalancer
kubectl apply -f nginx.yaml