crictl provides a CLI for CRI-compatible container runtimes. This allows the CRI runtime developers to debug their runtime without needing to set up Kubernetes components.
crictl is currently in Beta and still under quick iterations. It is hosted at the cri-tools repository. We encourage the CRI developers to report bugs or help extend the coverage by adding more functionalities.
crictl can be downloaded from cri-tools release page:
VERSION="v1.0.0-beta.1"
wget https://github.com/kubernetes-incubator/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz
crictl SUBCOMMAND [FLAGS]
Subcommands includes:
attach
: Attach to a running containercreate
: Create a new containerexec
: Run a command in a running containerversion
: Display runtime version informationimages
: List imagesinspect
: Display the status of one or more containersinspecti
: Return the status of one ore more imagesinspectp
: Display the status of one or more podslogs
: Fetch the logs of a containerport-forward
: Forward local port to a podps
: List containerspull
: Pull an image from a registryrunp
: Run a new podrm
: Remove one or more containersrmi
: Remove one or more imagesrmp
: Remove one or more podspods
: List podsstart
: Start one or more created containersinfo
: Display information of the container runtimestop
: Stop one or more running containersstopp
: Stop one or more running podsupdate
: Update one or more running containersconfig
: Get and set crictl optionsstats
: List container(s) resource usage statisticscompletion
: Output bash shell completion codehelp, h
: Shows a list of commands or help for one command
crictl connects to unix:///var/run/dockershim.sock
by default. For other runtimes, the endpoint can be set in three ways:
- By setting flags
--runtime-endpoint
and--image-endpoint
- By setting environment variables
CONTAINER_RUNTIME_ENDPOINT
andIMAGE_SERVICE_ENDPOINT
- By setting the endpoint in the config file
--config=/etc/crictl.yaml
$ cat /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
image-endpoint: unix:///var/run/dockershim.sock
timeout: 10
debug: true
--runtime-endpoint
,-r
: CRI server runtime endpoint (default: "unix:///var/run/dockershim.sock").The default server is dockershim. If we want to debug other CRI server such as frakti, we can add flag--runtime-endpoint=/var/run/frakti.sock
--image-endpoint
,-i
: CRI server image endpoint, default same as runtime endpoint.--timeout
,-t
: Timeout of connecting to server (default: 10s)--debug
,-D
: Enable debug output--help
,-h
: show help--version
,-v
: print the version information of crictl--config
,-c
: Config file in yaml format. Overrided by flags or environment variables.
$ cat pod-config.json
{
"metadata": {
"name": "nginx-sandbox",
"namespace": "default",
"attempt": 1,
"uid": "hdishd83djaidwnduwk28bcsb"
},
"logDirectory": "/tmp",
"linux": {
}
}
$ crictl runp pod-config.json
f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f
List pod sandboxes and check the sandbox is in Ready state:
$ crictl pods
POD ID CREATED STATE NAME NAMESPACE ATTEMPT
f84dd361f8dc5 17 seconds ago Ready busybox-sandbox default 1
$ crictl pull busybox
Image is up to date for busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47
List images and check the busybox image has been pulled:
$ crictl images
IMAGE TAG IMAGE ID SIZE
busybox latest 8c811b4aec35f 1.15MB
k8s.gcr.io/pause 3.1 da86e6ba6ca19 742kB
$ cat pod-config.json
{
"metadata": {
"name": "nginx-sandbox",
"namespace": "default",
"attempt": 1,
"uid": "hdishd83djaidwnduwk28bcsb"
},
"log_directory": "/tmp",
"linux": {
}
}
$ cat container-config.json
{
"metadata": {
"name": "busybox"
},
"image":{
"image": "busybox"
},
"command": [
"top"
],
"log_path":"busybox/0.log",
"linux": {
}
}
$ crictl create f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f container-config.json pod-config.json
3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
List containers and check the container is in Created state:
$ crictl ps -a
CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
3e025dd50a72d busybox 32 seconds ago Created busybox 0
$ crictl start 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
$ crictl ps
CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
3e025dd50a72d busybox About a minute ago Running busybox 0
crictl exec -i -t 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60 ls
bin dev etc home proc root sys tmp usr var
Visit kubernetes-incubator/cri-tools for more information.