In this lab, you will deploy some Kubernetes Pods and perform some lifecycle and troubleshooting operations to get familiar with the command line utilities.
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.
First run a pod with an imperative command by running:
kubectl run nginx --image=nginx
When the command completes, check to see what pods are running by using the following command:
kubectl get pods
Use the YAML file provided in this lab named nginx2.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx2
spec:
containers:
- name: nginx
image: nginx:1.22.0
ports:
- containerPort: 80
Apply the yaml file by running:
kubectl apply -f nginx2.yaml
Check to see the status of the pods by running:
kubectl get pods
The command should return the pod from step 2 and the pod from step 3.
To limit your get request to the API server, you can specify the name of the pod such as:
kubectl get pod nginx2
Deploy an ubuntu pod where it writes "Ubuntu has started!" to the stdout by running the imperative command:
kubectl run ubuntu --image=ubuntu -- echo "Ubuntu has started!"
Check the status of the pod which should be starting, completing, and backing off before repeating the process.
kubectl get pod ubuntu
Dig deeper by running a describe command to list the Events
that have occurred when deploying the pod.
kubectl describe pod ubuntu
Any stdout messages in a container can be queried through the Kubernetes API server by running the logs command. View any logs of the ubuntu container by running:
kubectl logs ubuntu
"Why exactly did the log say, "Ubuntu is started!"?
hint: it comes from the command we used to start the container.
Sometimes you might want to get the YAML of a running container. You can do this by running:
kubectl get pod ubuntu -o yaml
The result is that the API server returns the declarative YAML that can be used to build a new Kubernetes manifest if you like.
Note: There are more fields in this YAML than we've covered in lectures.
Delete the pods created during this lab by running:
kubectl delete pods ubuntu nginx nginx2
For extra credit, deploy your own pod or use one from earlier in this lab.
Exec into the pod to perform some commands and then exit the container.
Hint 1: `kubectl exec -it [podname] -- /bin/sh (or /bin/bash or other)
Hint 2: To exit the container run
exit
When done, delete the pod.
Open a second terminal window and run:
kubectl get pods --watch
Then in the other terminal window, deploy and delete some pods of your choosing.
What did you find in the terminal where the --watch
command was running?
When you're finished, delete your pods and use Ctrl+c to exit the --watch command