Kubernetes as a Service
- Cloud providers like AWS, Azure and GCP offer k8s as a service.
- K8s as a service means
- control plane will be managed by cloud provider and depending on your pricing plan this might me single node or multi node. you cannot ssh into control plane. To deal with control plane use kubectl or cloud provider web interface.
- nodes:
- Node as VM: In this case we select number of vms and this node will be added to control plane. for grouping they would give the option of node group. They also give option to autoscale nodes on demand (cluster autoscaling).
- Serverless or pay per pod.
- AWS offer k8s as a service => Elastic Kubernetes Services
- Azure => Azure Kuberntes services
-
GCP => Google Kuberentes Engine.
-
Cluster creation options
- Console/portal
- CLI
- Terraform
Lets create an AKS Cluster (Free control plane) using azure cli
export RESOURCE_GROUP="myAKSResourceGroup"
export CLUSTER_NAME="myAKSCluster"
export USER_NP='userpool1'
export LOCATION="eastus"
az group create --name $RESOURCE_GROUP --location $LOCATION
az aks create --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --node-count 1 --generate-ssh-keys
az aks nodepool add --resource-group $RESOURCE_GROUP --cluster-name $CLUSTER_NAME --name $USER_NP --node-count 1 --mode User
az aks nodepool list --resource-group $RESOURCE_GROUP --cluster-name $CLUSTER_NAME --query "[].{Count:count, Mode:mode, NodePool:name, ResourceGroup:resourceGroup}"
- Open git bash connect to the cluster
export RESOURCE_GROUP="myAKSResourceGroup"
export CLUSTER_NAME="myAKSCluster"
export USER_NP='userpool1'
export LOCATION="eastus"
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
az group delete --name $RESOURCE_GROUP --no-wait --yes
Creating the AKS cluster using terraform
winget install -e --id Hashicorp.Terraform
- Create a new folder called as aks-terrform
- create a file called as main.tf with the following content
terraform {
required_version = ">= 1.5.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0"
}
}
}
provider "azurerm" {
features {}
}
#############################
# Variables
#############################
variable "resource_group_name" {
default = "myAKSResourceGroup"
}
variable "cluster_name" {
default = "myAKSCluster"
}
variable "location" {
default = "eastus"
}
variable "user_nodepool_name" {
default = "userpool1"
}
#############################
# Resource Group
#############################
resource "azurerm_resource_group" "aks" {
name = var.resource_group_name
location = var.location
}
#############################
# AKS Cluster
#############################
resource "azurerm_kubernetes_cluster" "aks" {
name = var.cluster_name
location = azurerm_resource_group.aks.location
resource_group_name = azurerm_resource_group.aks.name
dns_prefix = "${var.cluster_name}-dns"
sku_tier = "Free"
default_node_pool {
name = var.user_nodepool_name
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "azure"
load_balancer_sku = "standard"
}
tags = {
Environment = "Demo"
}
}
#############################
# Get AKS Credentials
#############################
resource "null_resource" "get_credentials" {
depends_on = [
azurerm_kubernetes_cluster.aks
]
provisioner "local-exec" {
command = <<EOT
az aks get-credentials \
--resource-group ${azurerm_resource_group.aks.name} \
--name ${azurerm_kubernetes_cluster.aks.name} \
--overwrite-existing
EOT
}
triggers = {
cluster_id = azurerm_kubernetes_cluster.aks.id
}
}
# cd into folder with main.tf
terraform init
terraform apply -auto-approve
kubectl get nodes
terraform destroy