Differences between revisions 13 and 17 (spanning 4 versions)
Revision 13 as of 2019-11-26 03:29:54
Size: 2286
Editor: PieterSmit
Comment:
Revision 17 as of 2022-10-21 00:19:58
Size: 2907
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
$ kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq '.items | .[] | select(.metadata.name|test("pod-a"))' | head -n 200
Line 8: Line 10:
 * Verify the metrics server used in k8s {{{
$ kubectl describe apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io

}}}
Line 20: Line 26:
# Get pod details (swap requests for limits, or cpu for mem
kubectl get po --all-namespaces -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]} {.name}:{.resources.requests.cpu}{'\n'}{end}{'\n'}{end}
Line 23: Line 31:
or

kubectl describe nodes
Line 38: Line 49:
kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq .
Line 46: Line 57:
kubectl -n kube-system get configmap cluster-autoscaler-status -o yaml

Kubernetes K8s/Monitoring

  • Actual cpu usage, not requested

    $ kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods
    $ kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq '.items | .[] | select(.metadata.name|test("pod-a"))' | head -n 200
  • Verify the metrics server used in k8s

    $ kubectl describe apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io
  • Events happening in cluser

    kubectl -n kube-system get events --sort-by='{.lastTimestamp}'
    
    kubectl -n kube-system get events -w
    
    kubectl get events --field-selector type=Warning -w &
    
    kubectl get pods -A -w -o wide | grep "^\|Running\|Terminating" &
  • Node cpu and memory utilization

    # Get pod details  (swap requests for limits, or cpu for mem
    kubectl get po --all-namespaces -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]}  {.name}:{.resources.requests.cpu}{'\n'}{end}{'\n'}{end}
    
    alias util='kubectl get nodes | grep node | awk '\''{print $1}'\'' | xargs -I {} sh -c '\''echo   {} ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- ; echo '\'''
    
    or
    
    kubectl describe nodes
  • Watch node events (& puts it in background on terminal)

    kubectl get pods -A -o wide &
  • Get cpu metrics

    # CPU for singel pod
    kubectl top pod pd-691234f8-rabcw
    
    # Get the metrics for all nodes
    kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes | jq
    
    # Get the metrics for all pods
    kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq .
    
    # Get metrics.
    kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespaces/<namespace-name>/pods/<pod-name>

# k8s cluster auto scaler

kubectl -n kube-system describe configmap cluster-autoscaler-status
kubectl -n kube-system get      configmap cluster-autoscaler-status -o yaml

Add a sniffer as a sidecart to a pod

  • edit deployment and add

    - name: tcpdump
       image: corfr/tcpdump
       command:
         - /bin/sleep
         - infinity

Capture console log lines on termination

terminationMessagePolicy: FallbackToLogsOnError

https://kubernetes.io/docs/tasks/debug-application-cluster/determine-reason-pod-failure/#writing-and-reading-a-termination-message

Moreover, users can set the terminationMessagePolicy field of a Container for further customization. This field defaults to “File” which means the termination messages are retrieved only from the termination message file. By setting the terminationMessagePolicy to “FallbackToLogsOnError”, you can tell Kubernetes to use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller.


CategoryK8sKubernetes

k8s/Monitoring (last edited 2022-10-21 00:19:58 by PieterSmit)