Pod sandboxing on AKS uses Kata Containers to run each sandboxed pod in a lightweight virtual machine (VM) with its own guest kernel. This compute boundary isolates the workload from the host kernel and workloads in other pod VMs. To learn about the architecture, benefits, and use cases, see Overview of Pod sandboxing in Azure Kubernetes Service (AKS).
In this article, you deploy Pod sandboxing on a new or existing Azure Linux AKS cluster, deploy an application with the Kata runtime, and optionally verify kernel isolation.
For clusters that use node auto-provisioning (NAP), follow Use Pod sandboxing with node auto-provisioning instead of the Azure CLI node pool creation steps.
Deploying Pod sandboxing by using Kata Containers is similar to the standard runc workflow to deploy containers. Clusters with Pod sandboxing enabled come with a specific runtime class that you can reference in a pod manifest, runtimeClassName: kata-vm-isolation (GA). For more information about runtime class defaults and customization, see Considerations for Pod sandboxing.
Limitations
The following constraints apply to Pod sandboxing with kata-vm-isolation:
- Kata containers might not reach the IOPS performance limits that traditional containers can reach on Azure Files and high-performance local SSD.
- [Microsoft Defender for Containers][defender-for-containers] doesn't support assessing Kata runtime pods.
- Kata host-network access isn't supported. You can't directly access host networking configuration from within the pod VM.
- CPU and memory allocation differs from
runc. Each Kata pod runs in a pod VM whose size comes from pod limits:
- Pod sandboxing is supported only on Azure Linux. Ubuntu, Windows, and Azure Container Linux aren't supported. For more information, see Azure Linux container host for AKS.
- You can't enable Federal Information Processing Standard (FIPS) or Trusted Launch on a node pool that uses Pod sandboxing.
- Arm64 architecture isn't supported on a node pool that uses Pod sandboxing.
Prerequisites
- The Azure CLI version 2.80.0 or later. Run
az --version to find the version of your Azure CLI, and run az upgrade to upgrade. For more details, see the steps at Install Azure CLI.
- AKS supports Pod sandboxing on Kubernetes version 1.27.0 and higher. NAP-provisioned Pod sandboxing nodes require Kubernetes version 1.32 or later and Azure Linux 3.
- To manage a Kubernetes cluster, use the Kubernetes command-line client
kubectl. Azure Cloud Shell comes with kubectl. You can install kubectl locally using the az aks install-cli command.
Create a cluster with Pod sandboxing
Perform the following steps to deploy an Azure Linux AKS cluster using the Azure CLI.
Create an AKS cluster by running the az aks create command with the following parameters:
| Parameter |
Required value |
Notes |
--workload-runtime |
KataVmIsolation |
Enables Pod sandboxing on the node pool. |
--os-sku |
AzureLinux |
Pod sandboxing supports only the Azure Linux OS SKU. |
--node-vm-size |
A generation 2 VM size that supports nested virtualization |
For example, use a [Dsv3-series][dv3-series] VM size. |
--node-count |
3 |
Creates three nodes for this example. Adjust the value for your workload. |
The following example creates a cluster named myAKSCluster with three nodes in myResourceGroup:
az aks create \
--name myAKSCluster \
--resource-group myResourceGroup \
--os-sku AzureLinux \
--workload-runtime KataVmIsolation \
--node-vm-size Standard_D4s_v3 \
--node-count 3 \
--generate-ssh-keys
Run the following command to get access credentials for the Kubernetes cluster. Use the az aks get-credentials command and replace the values for the cluster name and the resource group name.
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
List all Pods in all namespaces by running the kubectl get pods command.
kubectl get pods --all-namespaces
Enable Pod sandboxing on an existing cluster
To use this feature with an existing AKS cluster, the following requirements must be met:
Add a node pool to your AKS cluster by using the az aks nodepool add command with the following parameters:
| Parameter |
Required value |
Notes |
--resource-group |
The resource group that contains the existing AKS cluster |
For example, use myResourceGroup. |
--cluster-name |
The name of the existing AKS cluster |
For example, use myAKSCluster. |
--name |
A unique node pool name |
For example, use nodepool2. |
--workload-runtime |
KataVmIsolation |
Enables Pod sandboxing on the node pool. |
--os-sku |
AzureLinux |
Pod sandboxing supports only the Azure Linux OS SKU. |
--node-vm-size |
A generation 2 VM size that supports nested virtualization |
For example, use a [Dsv3-series][dv3-series] VM size. |
--node-count |
1 |
Creates one node for this example. Adjust the value for your workload. |
The following example adds a node pool to myAKSCluster with one node in nodepool2 in the myResourceGroup:
az aks nodepool add --cluster-name myAKSCluster --resource-group myResourceGroup --name nodepool2 --os-sku AzureLinux --workload-runtime KataVmIsolation --node-vm-size Standard_D4s_v3 --node-count 1
Verify that the node pool was added successfully and that the Pod sandboxing node pool uses the expected workload runtime, OS SKU, and VM size.
az aks show \
--name myAKSCluster \
--resource-group myResourceGroup \
--query provisioningState \
--output tsv
az aks nodepool show \
--cluster-name myAKSCluster \
--resource-group myResourceGroup \
--name nodepool2 \
--query "{workloadRuntime:workloadRuntime, osSku:osSku, vmSize:vmSize}" \
--output table
The cluster provisioning state should be Succeeded. The node pool output should show KataVmIsolation, AzureLinux, and the VM size you selected.
NAP supports pod sandboxing through the spec.workloadRuntime field on an AKSNodeClass. Use a Karpenter NodePool that references this class to provision nodes for Kata workloads, rather than creating an Azure CLI-managed node pool with az aks nodepool add.
Prerequisites for NAP
- Enable NAP on your cluster. For setup instructions, see Enable node auto-provisioning.
- Use Kubernetes version 1.32 or later. NAP requires Azure Linux 3 for the Kata-enabled image.
- Set
imageFamily: AzureLinux and workloadRuntime: KataVmIsolation on the AKSNodeClass. Don't enable FIPS or Trusted Launch.
- Allow compatible AMD64, generation 2 VM sizes in your
NodePool requirements. Karpenter automatically filters for virtualization-capable sizes and selects the Kata-enabled image. You don't need to specify a VM size or add architecture and generation requirements to enable this filtering.
Create the NAP resources and verify the runtime class before you deploy a workload.
Save the following manifest as kata-nap.yaml. The NodePool references the Kata-enabled AKSNodeClass. The Cilium label and startup taint follow the NAP node pool configuration for clusters that use Cilium.
apiVersion: karpenter.azure.com/v1beta1
kind: AKSNodeClass
metadata:
name: kata
spec:
imageFamily: AzureLinux
workloadRuntime: KataVmIsolation
---
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: kata
spec:
template:
metadata:
labels:
kubernetes.azure.com/ebpf-dataplane: cilium
spec:
nodeClassRef:
group: karpenter.azure.com
kind: AKSNodeClass
name: kata
startupTaints:
- key: node.cilium.io/agent-not-ready
effect: NoExecute
value: "true"
requirements:
- key: kubernetes.io/os
operator: In
values: ["linux"]
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand"]
If your cluster doesn't use Cilium, omit the kubernetes.azure.com/ebpf-dataplane: cilium label and the node.cilium.io/agent-not-ready startup taint.
Apply the resources:
kubectl apply -f kata-nap.yaml
kubectl get aksnodeclass kata
kubectl get nodepool kata
Verify that the AKS-managed kata-vm-isolation runtime class is available:
kubectl get runtimeclass kata-vm-isolation -o yaml
The runtime class specifies the kubernetes.azure.com/kata-vm-isolation: "true" scheduling selector. When you create a pod that references this runtime class, Kubernetes adds the selector and runtime overhead to the pod. Karpenter recognizes the selector when it provisions compatible nodes and accounts for runtime overhead during bin-packing. You don't need to add the Kata selector manually.
Deploy and verify a NAP-managed Kata workload
Deploy a pod that requests the Kata runtime to trigger provisioning.
Save the following manifest as kata-nap-app.yaml. Set resource requests and limits to account for your workload and the pod VM's guest components. For sizing guidance, see Pod sandboxing considerations.
apiVersion: v1
kind: Pod
metadata:
name: nap-isolated-pod
spec:
runtimeClassName: kata-vm-isolation
containers:
- name: kata
image: mcr.azk8s.cn/aks/fundamental/base-ubuntu:v0.0.11
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5; done"]
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: "1"
memory: 512Mi
runtimeClassName is sufficient to select Kata-capable nodes. To target this specific Karpenter NodePool, optionally add the following to the pod specification:
nodeSelector:
karpenter.sh/nodepool: kata
Apply the pod manifest and wait for the pod to become ready:
kubectl apply -f kata-nap-app.yaml
kubectl wait --for=condition=Ready pod/nap-isolated-pod --timeout=10m
Karpenter provisions a compatible node if existing capacity can't accommodate the pod. Setting workloadRuntime: KataVmIsolation enables an additional runtime; standard pods can still run on the same node without VM isolation.
Verify that the pod runs on a Kata-enabled, NAP-managed node:
kubectl get nodes -l 'karpenter.sh/nodepool=kata,kubernetes.azure.com/kata-vm-isolation=true'
kubectl get pod nap-isolated-pod -o wide
kubectl exec nap-isolated-pod -- uname -r
kubectl get node "$(kubectl get pod nap-isolated-pod -o jsonpath='{.spec.nodeName}')" \
-o jsonpath='{.status.nodeInfo.kernelVersion}{"\n"}'
The pod's guest kernel differs from the node's host kernel. For another comparison using a standard pod, see Verify kernel isolation.
For field defaults, compatibility constraints, and the effect of changing the runtime on existing nodes, see Workload runtime and Pod sandboxing.
Deploy applications using Pod sandboxing
By using Pod sandboxing, you can deploy a mix of standard pods that don't use the Kata runtime alongside Kata pods that use the runtime.
The runtime class selects the Kata runtime, but you should also define scheduling constraints when you need workloads to run on a specific Pod sandboxing node pool. For an Azure CLI-managed node pool, use the built-in AKS node pool label in a nodeSelector. Replace nodepool2 with the name of your Pod sandboxing node pool. For a NAP-managed node pool, use karpenter.sh/nodepool instead, as shown in the NAP walkthrough.
spec:
runtimeClassName: kata-vm-isolation
nodeSelector:
kubernetes.azure.com/agentpool: nodepool2
For stronger separation, you can taint the Pod sandboxing node pool and add a matching toleration to Kata workloads. A taint without a matching toleration prevents other workloads from scheduling on that node pool. For more information, see Use node taints in an AKS cluster.
Deploy an application with the Kata runtime
To deploy a pod with the Kata runtime on your AKS cluster, perform the following steps.
Create a file named kata-app.yaml to describe your Kata pod, and then paste the following manifest.
kind: Pod
apiVersion: v1
metadata:
name: isolated-pod
spec:
runtimeClassName: kata-vm-isolation
containers:
- name: kata
image: mcr.azk8s.cn/aks/fundamental/base-ubuntu:v0.0.11
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
Deploy the Kubernetes pod by running the kubectl apply command and specify your kata-app.yaml file:
kubectl apply -f kata-app.yaml
The output of the command resembles the following example:
pod/isolated-pod created
Troubleshooting
Reconcile cluster configuration after adding a Pod sandboxing node pool (optional)
In most cases, az aks nodepool add is sufficient and no extra reconcile step is required. If the runtime class or node labels don't appear as expected after adding a Pod sandboxing node pool, run az aks update and then recheck.
az aks update --name myAKSCluster --resource-group myResourceGroup
Verify kernel isolation (optional)
This section uses the isolated-pod Kata pod (runtimeClassName: kata-vm-isolation) that you created in Deploy an application with the Kata runtime. If you didn't deploy that pod, deploy it now.
To compare the kernels of Kata and non-Kata pods, create a file named normal-app.yaml. The following manifest defines a standard pod without the Kata runtime:
kind: Pod
apiVersion: v1
metadata:
name: normal-pod
spec:
containers:
- name: non-kata
image: mcr.azk8s.cn/aks/fundamental/base-ubuntu:v0.0.11
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
Deploy the standard pod by using the kubectl apply command.
kubectl apply -f normal-app.yaml
To access a container inside the AKS cluster, start a shell session by running the kubectl exec command. In this example, you're accessing the container inside isolated-pod.
kubectl exec -it isolated-pod -- /bin/sh
Kubectl connects to your cluster, runs /bin/sh inside the first container within isolated-pod, and forwards your terminal's input and output streams to the container's process. You can also start a shell session to the container hosting the non-Kata pod to see the differences.
After starting a shell session to the container from isolated-pod, run commands to verify that the kata container is running in a pod sandbox. It has a different kernel version compared to the non-Kata container outside the sandbox.
To see the kernel version run the following command:
uname -r
The following example resembles output from the pod sandbox kernel:
[user]/# uname -r
6.6.96.mshv1
Start a shell session to the container from normal-pod to verify the kernel output:
kubectl exec -it normal-pod -- /bin/bash
To see the kernel version run the following command:
uname -r
The following example resembles output from the VM that's running normal-pod, which is a different kernel than the Kata pod running within the pod sandbox:
6.6.100.mshv1-1.azl3
Clean up resources
When you finish evaluating this feature, clean up resources you no longer need to avoid Azure charges. If you deployed a new cluster as part of your evaluation, run the following az aks delete command to delete the AKS cluster.
az aks delete --resource-group myResourceGroup --name myAKSCluster
If you deployed Pod sandboxing on an existing cluster, you can remove the pods using the kubectl delete pod command.
kubectl get pods
kubectl delete pod <kata-pod-name>
If you followed the NAP walkthrough, remove its workload and NAP resources. Deleting the Karpenter NodePool also terminates its nodes, so first ensure that no workloads you want to retain are running on them.
kubectl delete -f kata-nap-app.yaml
kubectl delete nodepool kata
kubectl delete aksnodeclass kata
To remove an Azure CLI-managed Pod sandboxing node pool, use the az aks nodepool delete command. Before deleting the node pool, ensure no workloads that you want to retain are running on it.
az aks nodepool delete \
--cluster-name myAKSCluster \
--resource-group myResourceGroup \
--name nodepool2
Next steps
- Learn more about Azure Dedicated hosts for nodes with your AKS cluster to use hardware isolation and control over Azure platform maintenance events.
- To further explore Pod sandboxing isolation and explore workload scenarios, try out the Pod sandboxing labs.