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).
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-namespaceexists 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:
kubectl create namespace tkg-cluster-namespace
- Apply the YAML File:
kubectl apply -f my-tkg-cluster.yaml
- Monitor Cluster Creation:
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:
# 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:
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:
# 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:
tanzu cluster create --file workload-cluster-config.yaml
Leave a comment