@@ -19,15 +19,14 @@ Kubernetes node. `crictl` and its source are hosted in the
19
19
20
20
## {{% heading "prerequisites" %}}
21
21
22
-
23
22
` crictl ` requires a Linux operating system with a CRI runtime.
24
23
25
24
<!-- steps -->
26
25
27
26
## Installing crictl
28
27
29
- You can download a compressed archive ` crictl ` from the cri-tools [ release
30
- page] ( https://github.com/kubernetes-sigs/cri-tools/releases ) , for several
28
+ You can download a compressed archive ` crictl ` from the cri-tools
29
+ [ release page] ( https://github.com/kubernetes-sigs/cri-tools/releases ) , for several
31
30
different architectures. Download the version that corresponds to your version
32
31
of Kubernetes. Extract it and move it to a location on your system path, such as
33
32
` /usr/local/bin/ ` .
@@ -85,6 +84,7 @@ List all pods:
85
84
``` shell
86
85
crictl pods
87
86
```
87
+
88
88
The output is similar to this:
89
89
90
90
```
@@ -100,6 +100,7 @@ List pods by name:
100
100
``` shell
101
101
crictl pods --name nginx-65899c769f-wv2gp
102
102
```
103
+
103
104
The output is similar to this:
104
105
105
106
```
@@ -112,6 +113,7 @@ List pods by label:
112
113
``` shell
113
114
crictl pods --label run=nginx
114
115
```
116
+
115
117
The output is similar to this:
116
118
117
119
```
@@ -126,6 +128,7 @@ List all images:
126
128
``` shell
127
129
crictl images
128
130
```
131
+
129
132
The output is similar to this:
130
133
131
134
```
@@ -141,6 +144,7 @@ List images by repository:
141
144
``` shell
142
145
crictl images nginx
143
146
```
147
+
144
148
The output is similar to this:
145
149
146
150
```
@@ -153,6 +157,7 @@ Only list image IDs:
153
157
``` shell
154
158
crictl images -q
155
159
```
160
+
156
161
The output is similar to this:
157
162
158
163
```
@@ -169,6 +174,7 @@ List all containers:
169
174
``` shell
170
175
crictl ps -a
171
176
```
177
+
172
178
The output is similar to this:
173
179
174
180
```
@@ -181,9 +187,10 @@ CONTAINER ID IMAGE
181
187
182
188
List running containers:
183
189
184
- ```
190
+ ``` shell
185
191
crictl ps
186
192
```
193
+
187
194
The output is similar to this:
188
195
189
196
```
@@ -198,6 +205,7 @@ CONTAINER ID IMAGE
198
205
``` shell
199
206
crictl exec -i -t 1f73f2d81bf98 ls
200
207
```
208
+
201
209
The output is similar to this:
202
210
203
211
```
@@ -211,6 +219,7 @@ Get all container logs:
211
219
``` shell
212
220
crictl logs 87d3992f84f74
213
221
```
222
+
214
223
The output is similar to this:
215
224
216
225
```
@@ -224,6 +233,7 @@ Get only the latest `N` lines of logs:
224
233
``` shell
225
234
crictl logs --tail=1 87d3992f84f74
226
235
```
236
+
227
237
The output is similar to this:
228
238
229
239
```
@@ -236,98 +246,103 @@ Using `crictl` to run a pod sandbox is useful for debugging container runtimes.
236
246
On a running Kubernetes cluster, the sandbox will eventually be stopped and
237
247
deleted by the Kubelet.
238
248
239
- 1 . Create a JSON file like the following:
249
+ 1 . Create a JSON file like the following:
240
250
241
- ``` json
242
- {
243
- "metadata" : {
244
- "name" : " nginx-sandbox" ,
245
- "namespace" : " default" ,
246
- "attempt" : 1 ,
247
- "uid" : " hdishd83djaidwnduwk28bcsb"
248
- },
249
- "logDirectory" : " /tmp" ,
250
- "linux" : {
251
- }
252
- }
253
- ```
251
+ ``` json
252
+ {
253
+ "metadata" : {
254
+ "name" : " nginx-sandbox" ,
255
+ "namespace" : " default" ,
256
+ "attempt" : 1 ,
257
+ "uid" : " hdishd83djaidwnduwk28bcsb"
258
+ },
259
+ "logDirectory" : " /tmp" ,
260
+ "linux" : {
261
+ }
262
+ }
263
+ ```
254
264
255
- 2 . Use the `crictl runp` command to apply the JSON and run the sandbox.
265
+ 2 . Use the ` crictl runp ` command to apply the JSON and run the sandbox.
256
266
257
- ```shell
258
- crictl runp pod-config.json
259
- ```
267
+ ``` shell
268
+ crictl runp pod-config.json
269
+ ```
260
270
261
- The ID of the sandbox is returned.
271
+ The ID of the sandbox is returned.
262
272
263
273
### Create a container
264
274
265
275
Using ` crictl ` to create a container is useful for debugging container runtimes.
266
276
On a running Kubernetes cluster, the sandbox will eventually be stopped and
267
277
deleted by the Kubelet.
268
278
269
- 1 . Pull a busybox image
270
-
271
- ```shell
272
- crictl pull busybox
273
- Image is up to date for busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47
274
- ```
275
-
276
- 2 . Create configs for the pod and the container:
277
-
278
- **Pod config**:
279
- ```yaml
280
- {
281
- "metadata" : {
282
- "name" : " nginx-sandbox" ,
283
- "namespace" : " default" ,
284
- "attempt" : 1 ,
285
- "uid" : " hdishd83djaidwnduwk28bcsb"
286
- },
287
- "log_directory" : " /tmp" ,
288
- "linux" : {
289
- }
290
- }
291
- ```
292
-
293
- **Container config**:
294
- ```yaml
295
- {
296
- "metadata" : {
297
- "name" : " busybox"
298
- },
299
- "image" :{
300
- "image" : " busybox"
301
- },
302
- "command" : [
303
- " top"
304
- ],
305
- "log_path" :" busybox.log" ,
306
- "linux" : {
307
- }
308
- }
309
- ```
310
-
311
- 3 . Create the container, passing the ID of the previously-created pod, the
312
- container config file, and the pod config file. The ID of the container is
313
- returned.
314
-
315
- ```shell
316
- crictl create f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f container-config.json pod-config.json
317
- ```
318
-
319
- 4 . List all containers and verify that the newly-created container has its
320
- state set to `Created`.
321
-
322
- ```shell
323
- crictl ps -a
324
- ```
325
- The output is similar to this:
279
+ 1 . Pull a busybox image
280
+
281
+ ``` shell
282
+ crictl pull busybox
283
+ ```
284
+ ``` none
285
+ Image is up to date for busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47
286
+ ```
287
+
288
+ 2 . Create configs for the pod and the container:
289
+
290
+ ** Pod config** :
291
+
292
+ ``` json
293
+ {
294
+ "metadata" : {
295
+ "name" : " nginx-sandbox" ,
296
+ "namespace" : " default" ,
297
+ "attempt" : 1 ,
298
+ "uid" : " hdishd83djaidwnduwk28bcsb"
299
+ },
300
+ "log_directory" : " /tmp" ,
301
+ "linux" : {
302
+ }
303
+ }
304
+ ```
305
+
306
+ ** Container config** :
307
+
308
+ ``` json
309
+ {
310
+ "metadata" : {
311
+ "name" : " busybox"
312
+ },
313
+ "image" :{
314
+ "image" : " busybox"
315
+ },
316
+ "command" : [
317
+ " top"
318
+ ],
319
+ "log_path" :" busybox.log" ,
320
+ "linux" : {
321
+ }
322
+ }
323
+ ```
324
+
325
+ 3 . Create the container, passing the ID of the previously-created pod, the
326
+ container config file, and the pod config file. The ID of the container is
327
+ returned.
328
+
329
+ ``` shell
330
+ crictl create f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f container-config.json pod-config.json
331
+ ```
332
+
333
+ 4 . List all containers and verify that the newly-created container has its
334
+ state set to ` Created ` .
335
+
336
+ ``` shell
337
+ crictl ps -a
338
+ ```
339
+
340
+ The output is similar to this:
326
341
327
- ```
328
- CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
329
- 3e025 dd50a72d busybox 32 seconds ago Created busybox 0
330
- ```
342
+ ```
343
+ CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
344
+ 3e025dd50a72d busybox 32 seconds ago Created busybox 0
345
+ ```
331
346
332
347
### Start a container
333
348
@@ -336,6 +351,7 @@ To start a container, pass its ID to `crictl start`:
336
351
``` shell
337
352
crictl start 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60
338
353
```
354
+
339
355
The output is similar to this:
340
356
341
357
```
@@ -350,13 +366,12 @@ crictl ps
350
366
The output is similar to this:
351
367
352
368
```
353
- CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
354
- 3e025dd50a72d busybox About a minute ago Running busybox 0
369
+ CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT
370
+ 3e025dd50a72d busybox About a minute ago Running busybox 0
355
371
```
356
372
357
373
## {{% heading "whatsnext" %}}
358
374
359
375
* [ Learn more about ` crictl ` ] ( https://github.com/kubernetes-sigs/cri-tools ) .
360
- * [ Map ` docker ` CLI commands to ` crictl ` ] ( /reference/tools/map-crictl-dockercli/ ) .
376
+ * [ Map ` docker ` CLI commands to ` crictl ` ] ( /docs/ reference/tools/map-crictl-dockercli/ ) .
361
377
362
- <!-- discussion -->
0 commit comments