The Metrix server allows to collect CPU and memory data from the nodes and pods in the cluster. Install metrix server
-- clone metrix server repository
$ git clone -b release-0.3 --single-branch https://github.com/kubernetes-sigs/metrics-server.git
-- install metrix server
$ kubectl apply -f metrics-server/deploy/1.8+/
-- get metrix server information
$ kubectl get --raw /apis/metrics.k8s.io
-- view CPU and memory for the nodes
$ kubectl top node
-- view CPU and memory for the pods
$ kubectl top pods
-- view CPU and memory for the pods in all namespaces and kube-system
$ kubectl top pods --all-namespaces
$ kubectl top pods -n kube-system
-- view CPU and memory for the pods with selectors
$ kubectl top pods -l run=pod-with-defaults
-- view CPU and memory for the pods with pod_name
$ kubectl top pod pod-with-defaults
-- view CPU and memory for the pod's container
$ kubectl top pods group-context --containers
Liveness and readiness probes can be used to automatically restart containers if they are failing or automatically remove from a service point.
-- get service endpoint
$ kubectl get ep
The log directory for containers is in /var/log/containers
, which can potentially can consume all nodes disk spaces. To manage this use sidecar technique with a logging agent.
-- view the different type of logs
$ kubectl exec counter -- ls /var/log
-- view logs of a container in a pod
$ kubectl logs counter conunt-log-1
$ kubectl logs counter conunt-log-2
-- view the logs of nginx container
$ kubectl logs nginx
-- view logs of a container in a pod
$ kubectl logs counter -c conunt-log-1
-- view logs of all contianers
$ kubectl logs counter --all-containers=True
-- view logs of a container in a pod labeled nginx
$ kubectl logs -p -c nginx nginx
-- view logs of previously terminated container on pod nginx
$ kubectl logs counter conunt-log-1
-- tails the log for a pod
$ kubectl logs --tail=20 nginx
-- view the last 1 hour logs
$ kubectl logs --since=1h nginx
-- view the contianers logs from a deployment
$ kubectl logs deployment/nginx -c nginx
-- direct logs to a file
$ kubectl logs counter -c count-log-1 > counter.log
Table of Contents
Prev Chapter: Chapter 8: Security (12%)
Next Chapter: Chapter 10: Troubleshooting (10%)