Azure AKS

[TOC]

Azure AKS

Create Azure AKS via AZ CLI

  • Login Azure

    1
    az login
  • Create Azure resource group

    1
    az group create --name felix_test
  • Create Azure AKS Cluster

    1
    az aks create --resource-group felix_test --name K8sCluster --node-count 1 --generate-ssh-keys --node-vm-size=Standard_B2s --disable-rbac
  • Access AKS cluster through kubectl

    1
    2
    az aks get-credentials --resource-group=felix_test --name=K8sCluster
    Merged "K8sCluster" as current context in /Users/felix_yang/.kube/config

    image-20221230212633255

    all the configuration of Azure AKS cluster written into kubectl config file: /Users/felix_yang/.kube/config

  • Verify the access via Kubectl commands

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    felix_yang@nj-felix-yang-mba ~ % kubectl get nodes
    NAME STATUS ROLES AGE VERSION
    aks-nodepool1-19839722-vmss000000 Ready agent 6m2s v1.24.6

    felix_yang@nj-felix-yang-mba ~ % kubectl get namespaces
    NAME STATUS AGE
    default Active 19m
    kube-node-lease Active 19m
    kube-public Active 19m
    kube-system Active 19m


    felix_yang@nj-felix-yang-mba ~ % kubectl get pods --all-namespaces -o wide
    NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    kube-system azure-ip-masq-agent-5nb4w 1/1 Running 0 9m29s 10.224.0.4 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system cloud-node-manager-bjghg 1/1 Running 0 9m29s 10.224.0.4 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system coredns-59b6bf8b4f-9bnk9 1/1 Running 0 8m39s 10.244.0.8 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system coredns-59b6bf8b4f-sktkk 1/1 Running 0 19m 10.244.0.7 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system coredns-autoscaler-5655d66f64-dv487 1/1 Running 0 19m 10.244.0.5 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system csi-azuredisk-node-hkzb6 3/3 Running 0 9m29s 10.224.0.4 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system csi-azurefile-node-vgh7t 3/3 Running 0 9m29s 10.224.0.4 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system konnectivity-agent-676cb95b4d-dj9f5 1/1 Running 0 8m36s 10.244.0.9 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system konnectivity-agent-676cb95b4d-pfv8c 1/1 Running 0 19m 10.244.0.2 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system kube-proxy-9n8wm 1/1 Running 0 9m29s 10.224.0.4 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system metrics-server-7dd74d8758-vnkwn 2/2 Running 0 8m34s 10.244.0.11 aks-nodepool1-19839722-vmss000000 <none> <none>
    kube-system metrics-server-7dd74d8758-xvj5h 2/2 Running 0 8m34s 10.244.0.10 aks-nodepool1-19839722-vmss000000 <none> <none>
  • Delete AKS cluster

    1
    az aks delete --resource-group felix_test --name K8sCluster

Organizing Cluster Access Using kubeconfig Files

Use kubeconfig files to organize information about clusters, users, namespaces, and authentication mechanisms. The kubectl command-line tool uses kubeconfig files to find the information it needs to choose a cluster and communicate with the API server of a cluster.

Note: A file that is used to configure access to clusters is called a kubeconfig file. This is a generic way of referring to configuration files. It does not mean that there is a file named kubeconfig.

Warning: Only use kubeconfig files from trusted sources. Using a specially-crafted kubeconfig file could result in malicious code execution or file exposure. If you must use an untrusted kubeconfig file, inspect it carefully first, much as you would a shell script.

By default, kubectl looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag.

For step-by-step instructions on creating and specifying kubeconfig files, see Configure Access to Multiple Clusters.

Azure CLI Commands

  • use query to filter the output

    1
    2
    3
    4
    5
    6
    7
    8
    felix_yang@nj-felix-yang-mba ~ % az group list --query "[*].name"                        
    [
    "rg-vm-jpwest",
    "NetworkWatcherRG",
    "felix_test",
    "MC_felix_test_K8sCluster_eastus",
    "rg-vm-eastasia"
    ]

    https://jmespath.org/tutorial.html

  • set default subscription

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    az account set -s 138250aa-021a-4cb4-81ff-537da09d0e72

    felix_yang@nj-felix-yang-mba ~ % az account show
    {
    "environmentName": "AzureCloud",
    "homeTenantId": "3e04753a-ae5b-42d4-a86d-d6f05460f9e4",
    "id": "138250aa-021a-4cb4-81ff-537da09d0e72",
    "isDefault": true, ------------------------->>>> set to default
    "managedByTenants": [],
    "name": "Cloud Service Engineering lab test",
    "state": "Enabled",
    "tenantId": "3e04753a-ae5b-42d4-a86d-d6f05460f9e4",
    "user": {
    "name": "felix_yang@trendmicro.com",
    "type": "user"
    }
    }
  • image-20221230214050304

Azure AKS
https://blog.excelsre.com/1984/01/24/azure/
作者
Felix Yang
发布于
1984年1月24日
许可协议