-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
176 additions
and
0 deletions.
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
content/en/docs/tasks/debug-application-cluster/crictl.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
--- | ||
reviewers: | ||
- Random-Liu | ||
- feiskyer | ||
- mrunalp | ||
title: crictl | ||
--- | ||
|
||
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 GA since v1.11.0 and is hosted at the [cri-tools](https://github.com/kubernetes-incubator/cri-tools) repository. We encourage the CRI developers to report bugs or help extend the coverage by adding more functionalities. | ||
|
||
{{< toc >}} | ||
|
||
## Install crictl | ||
|
||
crictl can be downloaded from cri-tools [release page](https://github.com/kubernetes-incubator/cri-tools/releases): | ||
|
||
```sh | ||
VERSION="v1.11.0" | ||
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 | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
crictl SUBCOMMAND [FLAGS] | ||
``` | ||
|
||
Subcommands includes: | ||
|
||
- `attach`: Attach to a running container | ||
- `create`: Create a new container | ||
- `exec`: Run a command in a running container | ||
- `version`: Display runtime version information | ||
- `images`: List images | ||
- `inspect`: Display the status of one or more containers | ||
- `inspecti`: Return the status of one ore more images | ||
- `inspectp`: Display the status of one or more pods | ||
- `logs`: Fetch the logs of a container | ||
- `port-forward`: Forward local port to a pod | ||
- `ps`: List containers | ||
- `pull`: Pull an image from a registry | ||
- `runp`: Run a new pod | ||
- `rm`: Remove one or more containers | ||
- `rmi`: Remove one or more images | ||
- `rmp`: Remove one or more pods | ||
- `pods`: List pods | ||
- `start`: Start one or more created containers | ||
- `info`: Display information of the container runtime | ||
- `stop`: Stop one or more running containers | ||
- `stopp`: Stop one or more running pods | ||
- `update`: Update one or more running containers | ||
- `config`: Get and set crictl options | ||
- `stats`: List container(s) resource usage statistics | ||
- `completion`: Output bash shell completion code | ||
- `help, 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` and `IMAGE_SERVICE_ENDPOINT` | ||
- By setting the endpoint in the config file `--config=/etc/crictl.yaml` | ||
|
||
```sh | ||
# cat /etc/crictl.yaml | ||
runtime-endpoint: unix:///var/run/dockershim.sock | ||
image-endpoint: unix:///var/run/dockershim.sock | ||
timeout: 10 | ||
debug: true | ||
``` | ||
|
||
## Additional options | ||
|
||
- `--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. | ||
|
||
## Examples | ||
|
||
### Run pod sandbox with config file | ||
|
||
```sh | ||
# cat podsandbox-config.json | ||
{ | ||
"metadata": { | ||
"name": "nginx-sandbox", | ||
"namespace": "default", | ||
"attempt": 1, | ||
"uid": "hdishd83djaidwnduwk28bcsb" | ||
}, | ||
"linux": { | ||
} | ||
} | ||
|
||
# crictl runp podsandbox-config.json | ||
e1c83b0b8d481d4af8ba98d5f7812577fc175a37b10dc824335951f52addbb4e | ||
# crictl pods | ||
PODSANDBOX ID NAME STATE | ||
e1c83b0b8d481d4af8ba98d5f7812577fc175a37b10dc824335951f52addbb4e nginx-sandbox SANDBOX_READY | ||
``` | ||
|
||
### Pull a busybox image | ||
|
||
```sh | ||
# crictl pull busybox | ||
Image is update to date for busybox@sha256:b82b5740006c1ab823596d2c07f081084ecdb32fd258072707b99f52a3cb8692 | ||
# crictl images | ||
IMAGE TAG IMAGE ID SIZE | ||
busybox latest d20ae45477cbc 1.13MB | ||
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffaa 747kB | ||
``` | ||
|
||
### Create container in a pod sandbox with config file | ||
|
||
```sh | ||
# cat podsandbox-config.json | ||
{ | ||
"metadata": { | ||
"name": "nginx-sandbox", | ||
"namespace": "default", | ||
"attempt": 1, | ||
"uid": "hdishd83djaidwnduwk28bcsb" | ||
}, | ||
"linux": { | ||
} | ||
} | ||
|
||
# cat container-config.json | ||
{ | ||
"metadata": { | ||
"name": "busybox" | ||
}, | ||
"image":{ | ||
"image": "busybox" | ||
}, | ||
"command": [ | ||
"top" | ||
], | ||
"linux": { | ||
} | ||
} | ||
|
||
# crictl create e1c83b0b8d481d4af8ba98d5f7812577fc175a37b10dc824335951f52addbb4e container-config.json podsandbox-config.json | ||
0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 | ||
# crictl ps -a | ||
CONTAINER ID CREATED STATE NAME | ||
0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 1 minutes ago CONTAINER_CREATED busybox | ||
``` | ||
|
||
### Start container | ||
|
||
```sh | ||
# crictl start 0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 | ||
0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 | ||
# crictl ps | ||
CONTAINER ID CREATED STATE NAME | ||
0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 2 minutes ago CONTAINER_RUNNING busybox | ||
``` | ||
|
||
### Exec a command in container | ||
|
||
```sh | ||
# crictl exec -i -t 0a2c761303163f2acaaeaee07d2ba143ee4cea7e3bde3d32190e2a36525c8a05 ls | ||
bin dev etc home proc root sys tmp usr var | ||
``` | ||
|
||
## More information | ||
|
||
Visit [kubernetes-incubator/cri-tools](https://github.com/kubernetes-incubator/cri-tools) for more information. |