Azure Kubernetes Service

11th Apr 2024

You will learn:

  • creation of AKS Cluster
  • connection of kubectl and AKS

You must have the latest version of Azure client az and kubernetes clientkubectl installed. This is how to install the latest version and to the Ubuntu environment (also on WSL2) with a single command.

Log in to Azure and create a ResourceGroup

az login
az group create --name mrg --location eastus

Create a cluster composed of one node:

az aks create --resource-group mrg --name mycluster --node-count 1 --enable-addons monitoring --generate-ssh-keys

Creation will take some time. Another ResourceGroup will be created for resources related to the cluster infrastructure.

Connect the kubectl line client to the Azure Kubernetes cluster:

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

Verify that the connection works:

kubectl get nodes

Cubectl contexts

The kubectl command is able to manage multiple clusters at the same time. He uses so-called contexts for that. If the connection does not work, check the current context:

kubectl config get-contexts

You can change the current context with

kubectl config use-context

Try deploying this trial app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-back
spec:
  replicas: 1
  selector:
    matchLabels:
      app: azure-vote-back
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: azure-vote-back
        image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
        env:
        - name: ALLOW_EMPTY_PASSWORD
          value: "yes"
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 1
  selector:
    matchLabels:
      app: azure-vote-front
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: azure-vote-front
        image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front

This application cannot maintain its state or does not use persistent volumes.

Bibliography

  • https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough

Previous Post Next Post

Azure Kubernetes Service