1Container(Runtime) CLI Container(Runtime)
2
3
4
5 crictl provides a CLI for CRI-compatible container runtimes. This
6 allows the CRI runtime developers to debug their runtime without need‐
7 ing to set up Kubernetes components.
8
9
10 crictl is currently in Beta and still under quick iterations. It is
11 hosted at the cri-tools ⟨https://github.com/kubernetes-incubator/cri-
12 tools⟩ repository. We encourage the CRI developers to report bugs or
13 help extend the coverage by adding more functionalities.
14
15
17 crictl can be downloaded from cri-tools release page
18 ⟨https://github.com/kubernetes-incubator/cri-tools/releases⟩:
19
20
21 VERSION="v1.11.1"
22 wget https://github.com/kubernetes-incubator/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
23 sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
24 rm -f crictl-$VERSION-linux-amd64.tar.gz
25
26
27
29 crictl SUBCOMMAND [FLAGS]
30
31
32
33 Subcommands includes:
34
35 · attach: Attach to a running container
36
37 · create: Create a new container
38
39 · exec: Run a command in a running container
40
41 · version: Display runtime version information
42
43 · images: List images
44
45 · inspect: Display the status of one or more containers
46
47 · inspecti: Return the status of one ore more images
48
49 · inspectp: Display the status of one or more pods
50
51 · logs: Fetch the logs of a container
52
53 · port-forward: Forward local port to a pod
54
55 · ps: List containers
56
57 · pull: Pull an image from a registry
58
59 · runp: Run a new pod
60
61 · rm: Remove one or more containers
62
63 · rmi: Remove one or more images
64
65 · rmp: Remove one or more pods
66
67 · pods: List pods
68
69 · start: Start one or more created containers
70
71 · info: Display information of the container runtime
72
73 · stop: Stop one or more running containers
74
75 · stopp: Stop one or more running pods
76
77 · update: Update one or more running containers
78
79 · config: Get and set crictl options
80
81 · stats: List container(s) resource usage statistics
82
83 · completion: Output bash shell completion code
84
85 · help, h: Shows a list of commands or help for one command
86
87
88 crictl connects to unix:///var/run/dockershim.sock by default. For
89 other runtimes, the endpoint can be set in three ways:
90
91 · By setting flags --runtime-endpoint and --image-endpoint
92
93 · By setting environment variables CONTAINER_RUNTIME_ENDPOINT and
94 IMAGE_SERVICE_ENDPOINT
95
96 · By setting the endpoint in the config file --config=/etc/crictl.yaml
97
98
99 $ cat /etc/crictl.yaml
100 runtime-endpoint: unix:///var/run/dockershim.sock
101 image-endpoint: unix:///var/run/dockershim.sock
102 timeout: 10
103 debug: true
104
105
106
108 --runtime-endpoint, -r: CRI server runtime endpoint (default:
109 "unix:///var/run/dockershim.sock").The default server is dockershim. If
110 we want to debug other CRI server such as frakti, we can add flag
111 --runtime-endpoint=/var/run/frakti.sock
112
113 · --image-endpoint, -i: CRI server image endpoint, default same as run‐
114 time endpoint.
115
116 · --timeout, -t: Timeout of connecting to server (default: 10s)
117
118 · --debug, -D: Enable debug output
119
120 · --help, -h: show help
121
122 · --version, -v: print the version information of crictl
123
124 · --config, -c: Config file in yaml format. Overrided by flags or envi‐
125 ronment variables.
126
127
129 Run pod sandbox with config file
130 $ cat pod-config.json
131 {
132 "metadata": {
133 "name": "nginx-sandbox",
134 "namespace": "default",
135 "attempt": 1,
136 "uid": "hdishd83djaidwnduwk28bcsb"
137 },
138 "logDirectory": "/tmp",
139 "linux": {
140 }
141 }
142
143 $ crictl runp pod-config.json
144 f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f
145
146
147
148 List pod sandboxes and check the sandbox is in Ready state:
149
150
151 $ crictl pods
152 POD ID CREATED STATE NAME NAMESPACE ATTEMPT
153 f84dd361f8dc5 17 seconds ago Ready busybox-sandbox default 1
154
155
156
157 Pull a busybox image
158 $ crictl pull busybox
159 Image is up to date for busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47
160
161
162
163 List images and check the busybox image has been pulled:
164
165
166 $ crictl images
167 IMAGE TAG IMAGE ID SIZE
168 busybox latest 8c811b4aec35f 1.15MB
169 k8s.gcr.io/pause 3.1 da86e6ba6ca19 742kB
170
171
172
173 Create container in the pod sandbox with config file
174 $ cat pod-config.json
175 {
176 "metadata": {
177 "name": "nginx-sandbox",
178 "namespace": "default",
179 "attempt": 1,
180 "uid": "hdishd83djaidwnduwk28bcsb"
181 },
182 "log_directory": "/tmp",
183 "linux": {
184 }
185 }
186
187 $ cat container-config.json
188 {
189 "metadata": {
190 "name": "busybox"
191 },
192 "image":{
193 "image": "busybox"
194 },
195 "command": [
196 "top"
197 ],
198 "log_path":"busybox/0.log",
199 "linux": {
200 }
201 }
202
203 $ crictl create f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f container-config.json pod-config.json
204 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
205
206
207
208 List containers and check the container is in Created state:
209
210
211 $ crictl ps -a
212 CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
213 3e025dd50a72d busybox 32 seconds ago Created busybox 0
214
215
216
217 Start container
218 $ crictl start 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
219 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
220
221 $ crictl ps
222 CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
223 3e025dd50a72d busybox About a minute ago Running busybox 0
224
225
226
227 Exec a command in container
228 crictl exec -i -t 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60 ls
229 bin dev etc home proc root sys tmp usr var
230
231
232
234 Visit kubernetes-incubator/cri-tools ⟨https://github.com/kubernetes-
235 incubator/cri-tools⟩ for more information.
236
237
238
239(CRI) Interface Container(Runtime)