---
# System prepended metadata

title: VMUG - Tanzu Lab Guide

---

# VMUG - Tanzu Lab Guide
## 1. Objectives
By the end of this lab, you will be able to:
* Configure TKG cluster
* Deploy container in tanzu k8s cluster
## 2. Setup TKG Cluster
### 2.1 Get CLI Tools.
**Step 1:** Log into vSphere Client https://192.160.20.2. Go to Inventory --> tanzu-cluster1 --> Summary tab. Click on “Open” link under Link to CLI Tools.

![](https://hackmd.io/_uploads/Bk9pKhjZT.png)

**Step 2:** Download CLI Plugin and unzip the downloaded file.

![](https://hackmd.io/_uploads/SyMu92sZp.png)

### 2.2 Connect to Supervisor Cluster

**Step 1:** Open CMD and go to the directory that CLI Plugin is saved and run below command to log into Tanzu supervisor cluster. 
```
kubectl vsphere login --server=192.160.40.129 --vsphere-username k8s-cluster-admin@vsphere.local --insecure-skip-tls-verify=true
```
![](https://hackmd.io/_uploads/SkpOo3sZa.png)
**Step 2:** Check current context and switch to the correct context.
```
kubectl config current-context    #Check current context.
kubectl config use-context tanzu-cluster1    #Switch to correct context.
```
![](https://hackmd.io/_uploads/SkJxHzR-p.png)

### 2.3 Deploy Tanzu k8s Cluster
**Step 1:** On your laptop, copy the following content, change the cluster name and create YAML file named as tk8s.yaml.
```
apiVersion: run.tanzu.vmware.com/v1alpha2
kind: TanzuKubernetesCluster
metadata:
  name: <k8s-cluster-name>
  namespace: tanzu-cluster1
spec:
  topology:
    controlPlane:
      replicas: 1
      vmClass: guaranteed-small
      storageClass: k8s-demo-storage
      tkr:
        reference:
          name: v1.22.9---vmware.1-tkg.1.cc71bc8
    nodePools:
    - name: worker-nodepool-a1
      replicas: 1
      vmClass: guaranteed-small
      storageClass: k8s-demo-storage
      volumes:
        - name: containerd
          mountPath: /var/lib/containerd
          capacity:
            storage: 16Gi
      tkr:
        reference:
          name: v1.22.9---vmware.1-tkg.1.cc71bc8
  settings:
    storage:
      defaultClass: k8s-demo-storage
    network:
      cni:
        name: antrea
      services:
        cidrBlocks: ["198.53.100.0/16"]
      pods:
        cidrBlocks: ["192.0.5.0/16"]
      serviceDomain: cluster.local
```
**Step 2:** Create Tanzu K8s Cluster and wait till the status is ready (approximately 5-10min).
```
kubectl apply -f <yaml_file_location\tk8s.yaml>    #Deploy k8s cluster.
kubectl get tkc    #Check cluster status. 
```
![](https://hackmd.io/_uploads/BkAwXO6-T.png)

**Step 3:** Log into newly created Tanzu K8s Cluster.
```
kubectl vsphere login --server=192.160.40.129 --tanzu-kubernetes-cluster-name <newly_created_k8s_cluster_name> --tanzu-kubernetes-cluster-namespace tanzu-cluster1 --vsphere-username k8s-cluster-admin@vsphere.local --insecure-skip-tls-verify=true
```
![](https://hackmd.io/_uploads/r16vIu6-p.png)

**Step 4:** Create role-based access control using the default privileged PSP.
```
kubectl create clusterrolebinding default-tkg-admin-privileged-binding --clusterrole=psp:vmware-system-privileged --group=system:authenticated
```
## 3 Create Hello-World Container.
**Step 1:** Create namespace in Tanzu K8s Cluster.
```
kubectl create namespace k8s-deployments
```
![](https://hackmd.io/_uploads/SkRLPdaWT.png)
**Step 2:** On your laptop, copy the following content and create YAML named as hello-world.yaml.
```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world-gcr
  namespace: k8s-deployments
spec:
  selector:
    matchLabels:
      app: hello-world-gcr
  replicas: 1
  template:
    metadata:
      labels:
        app: hello-world-gcr
    spec:
      containers:
      - name: hello-world-gcr
        image: gcr.io/google-samples/node-hello:1.0
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: hello-world-gcr
  namespace: k8s-deployments
spec:
  type: LoadBalancer
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: hello-world-gcr
```
**Step 3:** Deploy Hello World container. After a few minutes, check deployment is ready.
```
kubectl apply -f <yaml_file_location\hello-world.yaml>    #Deploy Hello-World Container.
kubectl get deployments -A    #Check Deployment Status.
```
![](https://hackmd.io/_uploads/Sk_uP_aba.png)
**Step 4:** Check services and get load balancer External-IP and port. Open browser on your laptop and access to this page - *http://External_IP:8080*. “Hello Kubernetes!” message will be displayed.
```
kubectl get services -A
```
![](https://hackmd.io/_uploads/HJJqw_TWa.png)

> **Thank you for participating LAB.**