Module 8: Monitoring
This exercise focuses on enabling you to do the following:
-
Deploy and use the Kubernetes Dashboard
-
Deploy and use the Metrics Server
-
Explore Pod Logs in Kubernetes
NOTE: All the tasks in the following module are executed on the Kubernetes Master. You must SSH the rhel3 host in your labs, or copy the config file to the Windows jump host, in order to be able to execute the kubectl commands.
In this task, you will add the Dashboard to your Kubernetes Cluster.
Step | Action |
---|---|
Deploy the Kubernetes dashboard using Kubectl and the dashboard.yaml file from the git repository: kubectl create -f dashboard.yaml Note: if you upgraded your cluster to version 1.17, this task is obsolete, you can access your dashboard directly after starting the proxy. |
|
Using the command line prompt from your windows jump host, enter the following command: kubectl proxy --port=8082 |
|
Open a browser and visit the following website: http://localhost:8082/api/v1/namespaces/kube-dashboard/services/https:kubernetes-dashboard:/proxy/ |
|
Now we have to create a service account for the dashboard, and bind it with a role: kubectl create serviceaccount dashboard-admin kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=default:dashboard-admin |
|
List the secrets automatically created for the user and get the token information: kubectl get secrets kubectl describe secret <dashboard-admin-token-XXX> (from the command above) |
|
Go back to your browser and paste the token information (use a notepad to make sure it’s the right information): |
|
Verify that the dashboard appears: |
|
Browse the dashboard and discover information on it. | |
Click the plus sign to add a resource: |
|
Paste in the content from the alpine.yaml file from your ~/k8s/courses folder. |
|
Click Upload. | |
The Dashboard should redirect to the Workloads page with the Alpine Pod running. |
|
Continue to explore the Dashboard on your own. |
In the following task, you will deploy the Metrics Server in Kubernetes and learn how to access Kubernetes metrics. For more information regarding the Metrics Server, see: https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/
Step | Action |
---|---|
Make sure that you are in the ~/k8s/course/ folder on RHEL3. | |
Create two pods that are performing simulated workloads (one is CPU-intensive and the other is memory-intensive): kubectl create -f metrics-pods.yaml |
|
Install the Metrics Server: kubectl create -f metrics-server-setup.yaml |
|
Verify the Metrics Server was installed: kubectl get all -n kube-system | grep metrics
Sample output: pod/metrics-server-6dbcb4b8b-65krw 1/1 Running 3 18h service/metrics-server ClusterIP 10.104.68.215 <none> 443/TCP 18h deployment.apps/metrics-server 1/1 1 1 18h replicaset.apps/metrics-server-6dbcb4b8b 1 1 1 18h Note: There are other objects created are not associated with a namespace. |
|
Give the Metrics Server a few minutes to gather data. You can verify that the pods created in step 2-2 are generating load using: watch kubectl top node |
|
Using the output of the top command, which node consumes the most memory? | |
Using the output of the top command, which node consumes the most CPU? | |
Exit the top command using Ctrl-C. | |
Get the Metrics information about the current running pods using: kubectl top pods |
|
Using the output of the top command, which pod consumes the most memory? | |
Using the output of the top command, which pod consumes the most CPU? |
In this task, you will learn how gather logs from a Pod. For more information, see this: https://kubernetes.io/docs/concepts/cluster-administration/logging/
Step | Action |
---|---|
Make sure that you are in the ~/k8s/course/ on RHEL3. | |
Create a pod that exposes logs: kubectl create -f logging-pod.yaml |
|
Once deployed, analyze the Pod: kubectl describe pod |
|
How many containers are running in this Pod? | |
The Pod main container produces two logs with a sidecar container used to display each log. View the logs for /var/log/1.log. | |
View the logs for /var/log/2.log: kubectl logs main-1 -c main-log-2 |
End of Exercise