Deploying Tanzu Kubernetes Grid with YAML

In another post about automation, i tested the creation of Cloud Templates in Aria Automation using ChatGPT.

This can also be done for the kubernetes yaml files.

This YAML file describes a TKG workload cluster configuration, using Cluster API (CAPI).

  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: my-tkg-cluster
  namespace: tkg-cluster-namespace
spec:
  clusterNetwork:
    pods:
      cidrBlocks:
        - "192.168.0.0/16"
    services:
      cidrBlocks:
        - "10.96.0.0/12"
  controlPlaneRef:
    apiVersion: controlplane.cluster.x-k8s.io/v1beta1
    kind: KubeadmControlPlane
    name: my-tkg-control-plane
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: VSphereCluster
    name: my-vsphere-cluster

---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
  name: my-tkg-control-plane
  namespace: tkg-cluster-namespace
spec:
  version: v1.23.8
  replicas: 3
  infrastructureTemplate:
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: VSphereMachineTemplate
    name: my-control-plane-template
  kubeadmConfigSpec:
    clusterConfiguration:
      apiServer:
        extraArgs:
          cloud-provider: external
      controllerManager:
        extraArgs:
          cloud-provider: external
      etcd:
        local:
          imageRepository: projects.registry.vmware.com/tkg
          imageTag: v3.5.3_vmware.1
    initConfiguration:
      nodeRegistration:
        kubeletExtraArgs:
          cloud-provider: external
    joinConfiguration:
      nodeRegistration:
        kubeletExtraArgs:
          cloud-provider: external

---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: VSphereMachineTemplate
metadata:
  name: my-control-plane-template
  namespace: tkg-cluster-namespace
spec:
  template:
    spec:
      cloneMode: linkedClone
      numCPUs: 2
      memoryMiB: 8192
      diskGiB: 50
      network:
        devices:
          - networkName: "vm-network"
            dhcp4: true
      template: "ubuntu-2004-kube-v1.23.8"

---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
  name: my-tkg-worker-deployment
  namespace: tkg-cluster-namespace
spec:
  clusterName: my-tkg-cluster
  replicas: 3
  selector:
    matchLabels:
      cluster.x-k8s.io/cluster-name: my-tkg-cluster
  template:
    metadata:
      labels:
        cluster.x-k8s.io/cluster-name: my-tkg-cluster
    spec:
      version: v1.23.8
      bootstrap:
        configRef:
          apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
          kind: KubeadmConfigTemplate
          name: my-worker-template
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: VSphereMachineTemplate
        name: my-worker-machine-template

---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
  name: my-worker-template
  namespace: tkg-cluster-namespace
spec:
  template:
    spec:
      joinConfiguration:
        nodeRegistration:
          kubeletExtraArgs:
            cloud-provider: external

---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: VSphereMachineTemplate
metadata:
  name: my-worker-machine-template
  namespace: tkg-cluster-namespace
spec:
  template:
    spec:
      cloneMode: linkedClone
      numCPUs: 2
      memoryMiB: 4096
      diskGiB: 20
      network:
        devices:
          - networkName: "vm-network"
            dhcp4: true
      template: "ubuntu-2004-kube-v1.23.8"

Explanation:

  • apiVersion: Specifies the API version for the Tanzu Kubernetes Cluster resource.

  • kind: Specifies the type of resource, in this case, TanzuKubernetesCluster.

  • metadata: Contains metadata about the cluster, such as its name.

  • spec: Defines the specifications for the cluster.

topology: Specifies the cluster topology, including control plane and worker node configurations.

controlPlane: Configuration for the control plane nodes.

count: Number of control plane nodes.

  • class: Resource class for control plane nodes (e.g., best-effort-small).

  • storageClass: Storage class for the control plane nodes (e.g., vsphere-with-kubernetes).

  • workers: Configuration for worker nodes.

count: Number of worker nodes.

  • class: Resource class for worker nodes (e.g., best-effort-small).

  • storageClass: Storage class for the worker nodes (e.g., vsphere-with-kubernetes).

This YAML configuration creates a Tanzu Kubernetes Cluster named “example-cluster” with one control plane node and three worker nodes. It uses the specified resource classes and storage classes for provisioning the nodes. Adjust the configuration according to your requirements and the specifications of your environment.

Explanation of Key Elements

  • Namespace: Ensure the **tkg-cluster-namespace** exists or create it.

  • VSphereMachineTemplate:

Defines the specifications for the control plane and worker node VMs.

  • KubeadmControlPlane:

Sets the control plane parameters like the Kubernetes version and replicas.

  • MachineDeployment:

Describes the worker node pool and its configuration.

Usage Instructions

  • Create the Namespace:
1
kubectl create namespace tkg-cluster-namespace
  • Apply the YAML File:
1
kubectl apply -f my-tkg-cluster.yaml
  • Monitor Cluster Creation:
1
kubectl get clusters -n tkg-cluster-namespace

The Tanzu Management cluster:

Creating a YAML configuration file for deploying a Tanzu Kubernetes Grid (TKG) cluster involves defining specifications for the Kubernetes cluster within a VMware environment. Below, I provide a sample YAML file to deploy a TKG management cluster and a workload cluster.

Example YAML for TKG Management Cluster

The management cluster in Tanzu Kubernetes Grid acts as the central control plane through which workload clusters are deployed and managed. Here’s how you could define it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# management-cluster-config.yaml
---
CLUSTER_NAME: "tkg-management-cluster"
CLUSTER_PLAN: "prod"
INFRASTRUCTURE_PROVIDER: "vsphere"
VSPHERE_USERNAME: "vsphere-user"
VSPHERE_PASSWORD: "vsphere-password"
VSPHERE_SERVER: "vsphere-server.example.com"
VSPHERE_DATACENTER: "Datacenter"
VSPHERE_DATASTORE: "vsphere-datastore"
VSPHERE_NETWORK: "VM Network"
VSPHERE_RESOURCE_POOL: "*/Resources"
VSPHERE_FOLDER: "tkg-clusters"
VSPHERE_SSH_AUTHORIZED_KEY: "ssh-rsa AAAA..."
CONTROL_PLANE_MACHINE_TYPE: "medium"
NODE_MACHINE_TYPE: "medium"
NODE_MACHINE_COUNT: 3
KUBERNETES_VERSION: "v1.22.5+vmware.1-tkg.1-zshippable"

This presumes Tanzu CLI is set up with the necessary plugins.

then run:

1
tanzu management-cluster create --file management-cluster-config.yaml

Example YAML for TKG Workload Cluster

Now that you have a management cluster, you can deploy a workload cluster for your applications:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# workload-cluster-config.yaml
---
CLUSTER_NAME: "tkg-workload-cluster-01"
CLUSTER_PLAN: "dev"
INFRASTRUCTURE_PROVIDER: "vsphere"
NAMESPACE: "default"
VSPHERE_USERNAME: "vsphere-user"
VSPHERE_PASSWORD: "vsphere-password"
VSPHERE_SERVER: "vsphere-server.example.com"
VSPHERE_DATACENTER: "Datacenter"
VSPHERE_DATASTORE: "vsphere-datastore"
VSPHERE_NETWORK: "VM Network"
VSPHERE_RESOURCE_POOL: "*/Resources"
VSPHERE_FOLDER: "tkg-clusters"
VSPHERE_SSH_AUTHORIZED_KEY: "ssh-rsa AAAA..."
CONTROL_PLANE_MACHINE_TYPE: "small"
WORKER_MACHINE_TYPE: "small"
WORKER_MACHINE_COUNT: 3
KUBERNETES_VERSION: "v1.22.5+vmware.1-tkg.1-zshippable"

and create with:

1
tanzu cluster create --file workload-cluster-config.yaml