In this lab, you will deploy a Kubernetes service and use a test container to access the pods behind the service.
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=alphacluster
After successful authentication, change your Kubernetes context to the alphacluster by running:
kubectl config use-context alphacluster
Note: See the Authenticate lab for more a more detailed refresher on the procedures.
Use an nginx deployment and a Kubernetes service using the supplied yaml manifest.
---
apiVersion: v1
kind: Service
metadata:
name: myfirst-service
spec:
selector:
app: app1
tier: web
ports:
- protocol: TCP
port: 8080
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: app1
annotations:
kubernetes.io/change-cause: initial deployment
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
replicas: 3
selector:
matchLabels:
app: app1
template:
metadata:
name: nginx
labels:
app: app1
tier: web
spec:
containers:
- name: nginx
image: nginx:1.22.0
ports:
- containerPort: 80
Deploy the pods and services by running:
kubectl apply -f svc-manifest1.yaml
- List the service.
kubectl get services -o wide
- Describe the Service
kubectl describe service myfirst-service
- List the endpoints
kubectl get endpoints myfirst-service
- Delete one of your pods
kubectl get pods
kubectl delete pod [your_pod_name_here]
Question:
How does deleting a pod affect the cluster?
- Did a new pod get created to replace that deleted pod?
- How did the endpoints change?
- How might this affect access from other applications?
Run a container that has the curl command installed in the image. As an example: use the following imperative command to deploy a curl container and exec into a shell.
kubectl run curlpod -it --image=curlimages/curl -- sh
From the curl container run:
curl myfirst-service:8080
You should receive the html for the nginx welcome page.
Delete the deployments, replica sets, pods, and services.
kubectl delete -f svc-manifest1.yaml