Observability
Liveness and Readiness Probes
A Probe is a diagnostic performed periodically by the kubelet on a Container. To perform a diagnostic, the kubelet calls a Handler implemented by the Container. There are three types of handlers:
ExecAction: Executes a specified command inside the Container. The diagnostic is considered successful if the command exits with a status code of 0.
TCPSocketAction: Performs a TCP check against the Container’s IP address on a specified port. The diagnostic is considered successful if the port is open.
HTTPGetAction: Performs an HTTP Get request against the Container’s IP address on a specified port and path. The diagnostic is considered successful if the response has a status code greater than or equal to 200 and less than 400.
The kubelet can optionally perform and react to three kinds of probes on running Containers:
livenessProbe: Indicates whether the Container is running.
readinessProbe: Indicates whether the Container is ready to service requests.
startupProbe: Indicates whether the application within the Container is started.
Resources
OpenShift
IKS
References
apiVersion: v1kind: Podmetadata:name: my-podspec:containers:- name: appimage: busyboxcommand: ['sh', '-c', "echo Hello, Kubernetes! && sleep 3600"]
apiVersion: v1kind: Podmetadata:name: my-podspec:shareProcessNamespace: truecontainers:- name: appimage: bitnami/nginx
Container Logging
Application and systems logs can help you understand what is happening inside your cluster. The logs are particularly useful for debugging problems and monitoring cluster activity.
Kubernetes provides no native storage solution for log data, but you can integrate many existing logging solutions into your Kubernetes cluster.
Resources
OpenShift
IKS
References
apiVersion: v1kind: Podmetadata:name: counterspec:containers:- name: countimage: busyboxcommand: ['sh','-c','i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 5; done']
Get Logs
oc logs
Use Stern to View Logs
brew install sternstern . -n default
Get Logs
kubectl logs
Use Stern to View Logs
brew install sternstern . -n default
Monitoring Applications
To scale an application and provide a reliable service, you need to understand how the application behaves when it is deployed. You can examine application performance in a Kubernetes cluster by examining the containers, pods, services, and the characteristics of the overall cluster. Kubernetes provides detailed information about an application’s resource usage at each of these levels. This information allows you to evaluate your application’s performance and where bottlenecks can be removed to improve overall performance.
Prometheus, a CNCF project, can natively monitor Kubernetes, nodes, and Prometheus itself.
Resources
OpenShift
IKS
References
apiVersion: v1kind: Podmetadata:name: 500mspec:containers:- name: appimage: gcr.io/kubernetes-e2e-test-images/resource-consumer:1.4resources:
apiVersion: v1kind: Podmetadata:name: 200mspec:containers:- name: appimage: gcr.io/kubernetes-e2e-test-images/resource-consumer:1.4resources:
oc get projectsoc api-resources -o wideoc api-resources -o nameoc get nodes,ns,po,deploy,svcoc describe node --all
Verify Metrics is enabled
kubectl get --raw /apis/metrics.k8s.io/
Get Node Description
kubectl describe node
Check Resource Useage
kubectl top podskubectl top nodes
Activities
Task | Description | Link |
---|---|---|
Try It Yourself | ||
Probes | Create some Health & Startup Probes to find what’s causing an issue. | Probes |