In this lab, you will deploy a Kubernetes service and expose it outside of the Kubernetes cluster by using an external load balancer.
The Authentication token stored in your local KUBECONFIG file expires every 10 hours. You will want to re-authenticate to the TKG Service before starting the lab to ensure you have access to the Supervisor cluster.
Run:
kubectl vsphere login --server=[vSphere Control Plane Endpoint] --tanzu-kubernetes-cluster-namespace=poc --tanzu-kubernetes-cluster-name=alphaclusterAfter successful authentication, change your Kubernetes context to the alphacluster by running:
kubectl config use-context alphaclusterNote: See the Authenticate lab for more a more detailed refresher on the procedures.
Use a sample deployment and a Load Balancer Kubernetes service using the supplied yaml manifest.
apiVersion: v1
kind: Service
metadata:
name: myfirst-lbservice
spec:
selector:
app: game
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: game-deployment
labels:
app: game
annotations:
kubernetes.io/change-cause: Initial Deployment
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
replicas: 3
selector:
matchLabels:
app: game
template:
metadata:
name: game
labels:
app: game
spec:
containers:
- name: game
image: bsord/tetris
ports:
- containerPort: 80Deploy the pods and services by running:
kubectl apply -f lb-manifest.yaml- List the service.
kubectl get services -o wideQuestion: What is the Cluster IP of the Service?
Question: What is the External IP of the Service?
- Describe the Service
kubectl describe service myfirst-serviceQuestion: What port is the NodePort running on?
Open a web browser and navigate to the external-IP address of the Load Balancer service.
Take a minute just to make sure the container is workign correctly, by playing for just a bit... not too long, there is work to do!
Delete the deployments, replica sets, pods, and services.
kubectl delete -f lb-manifest.yaml