Skip to content

Instantly share code, notes, and snippets.

@rafzei
Last active October 12, 2022 10:28
Show Gist options
  • Save rafzei/69149606d0f5a49b39ace96c6d540f4e to your computer and use it in GitHub Desktop.
Save rafzei/69149606d0f5a49b39ace96c6d540f4e to your computer and use it in GitHub Desktop.
crictl commands
# crictl documentation: https://kubernetes.io/docs/tasks/debug-application-cluster/crictl/
# Runtime endpoints:
sudo crictl --runtime-endpoint unix:///run/containerd/containerd.sock
sudo crictl --runtime-endpoint unix:///var/run/dockershim.sock
sudo crictl --runtime-endpoint unix:///run/crio/crio.sock
## Containers
# Get all containers
sudo crictl ps
# Get container ID by name
sudo crictl ps --name=kube-apiserver -q
# Inspect container
sudo crictl inspect
# Stop force container
sudo crictl ps --name 'kube-apiserver' -q \
| xargs --no-run-if-empty sudo crictl stop --timeout=0
## Pods
# Get pods in all namespaces
sudo crictl pods
# Get the Pod ID of the Pod with crictl
POD_ID=$(sudo crictl pods --name=nginx-6f858d4d45-vnszm --namespace=default -q --no-trunc)
# Inspect Pod
sudo crictl inspectp
# Get the network namespace of this pod
NETNS=$(sudo crictl inspectp ${POD_ID} | jq -r '.info.runtimeSpec.linux.namespaces[] |select(.type=="network") | .path')
If this helped you, leave thumbs up in a comment :thumbsup:
@rafzei
Copy link
Author

rafzei commented Jan 24, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment