If you deploy a Tanzu Kubernetes cluster using a typical YAML file with no volumes defined you’ll end up with a fairly small worker node that can quickly fill up all available disk space with container images. Each time a container is deployed on a node Kubernetes makes a local copy of the container image file. Each image file can be 5GB or more. It doesn’t take long to fill up a workspace hard disk with images. If you just have one big root partition then filling up the hard disk will cause Kubernetes to crash.
To create a Kubernetes cluster you create a YAML file and run kubectl on it. The following YAML file builds a cluster based on the ubuntu-2204-amd64-v1.31.1—vmware.2-fips-vkr.2 TKR image, which is based on Ubuntu 22.04 and contains Kubernetes 1.31.1.
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TanzuKubernetesCluster
metadata:
name: my-tanzu-kubernetes-cluster-name
namespace: my-tanzu-kubernetes-cluster-namespace
annotations:
run.tanzu.vmware.com/resolve-os-image: os-name=ubuntu
spec:
topology:
controlPlane:
replicas: 3
vmClass: guaranteed-small
storageClass: vsan-default-storage-policy
tkr:
reference:
name: v1.31.1---vmware.2-fips-vkr.2
nodePools:
- name: worker
replicas: 3
vmClass: guaranteed-8xlarge
storageClass: vsan-default-storage-policy
volumes:
- name: containerd
mountPath: /var/lib/containerd
capacity:
storage: 160Gi
tkr:
reference:
name: v1.31.1---vmware.2-fips-vkr.2
In order to allocate a separate, larger volume for storing docker images on the worker nodes I added a volumes section. I have a storage class defined named vsan-default-storage-policy
and the volumes section will allocate a 160GiB volume using the disk specified by vsan-default-storage-policy
and mount it on the worker node using the path /var/lib/containerd
, which is where container images are stored. Change vsan-default-storage-policy
to the name of a storage policy defined for your tanzu-kubernetes-cluster-namespace
if you want this to work on your system.
Now if I fill up the volume with images I won’t be able to add more images, but my Kubernetes cluster will keep running.
Hope you find this useful.