Kubernetes utils
March 2, 2023

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.

Особенности.

1. Используется для CRI ContainerD;
2. Работа строится большей частью на уровне контейнеров, а не на уровне подов;
2. Ставится на ноду кластера.

Установка.

VERSION="v1.26.0" # check latest version in /releases page
wget https://github.com/kubernetes-sigs/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

COMMANDS:

   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, image, img  List images
   inspect             Display the status of one or more containers
   inspecti            Return the status of one or more images
   imagefsinfo         Return image filesystem info
   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
   run                 Run a new container inside a sandbox
   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 client configuration options
   stats               List container(s) resource usage statistics
   completion          Output shell completion code
   help, h             Shows a list of commands or help for one command
crictl ps
CONTAINER           IMAGE               CREATED             STATE               NAME                           ATTEMPT             POD ID
c6689fbac9d95       5dc814ae3a766       3 days ago          Running             cilium-operator                1                   fe00b546386f9
52f7e322ee693       2f66aad5324aa       3 days ago          Running             mypod                          0                   52d4489dfb373
93145e000e190       d3348bcdc1e7e       4 days ago          Running             cert-manager                   0                   315fb5a0e3d7e
58608563ae1f3       8eaca4249b016       4 days ago          Running             cert-manager                   0                   f4acc41ed52ce
9c9e66a3275bd       11778d29f8cc2       4 days ago          Running             cert-manager                   0                   95d45c2828654
ab405f341fd4f       717ff2a483f4d       10 days ago         Running             hubble-relay                   0                   7f3beeed99f54
b979627e609fe       b7db21b30ad90       10 days ago         Running             metrics-server-nanny           0                   46c7a28a5d697
ecf2e4a59b71c       e57a417f15d36       10 days ago         Running             metrics-server                 0                   46c7a28a5d697
ebb8e863a3d37       bf261d1579144       10 days ago         Running             coredns                        0                   11735ffc744c9
76783773d8b55       414151c8babd6       10 days ago         Running             node-problem-detector          0                   e9f8f445b9763
bbeb1e41c0701       14afc47fd5aff       10 days ago         Running             autoscaler                     0                   3639b1ff27d6b
acd38fe8fc03d       92bfa03945f0d       10 days ago         Running             liveness-probe-double          0                   437b4ec6c4d5a
5fe144bb15d93       2edbd4f01ccd4       10 days ago         Running             cilium-agent                   0                   9cc1a85a78811
9dfe97121d4e0       c2103589e99f9       10 days ago         Running             node-driver-registrar-double   0                   437b4ec6c4d5a
0776bd9a1049c       91b2502cca9dd       10 days ago         Running             yc-disk-csi-driver-double      0                   437b4ec6c4d5a
ec53c21694bb6       92bfa03945f0d       10 days ago         Running             liveness-probe                 0                   437b4ec6c4d5a
d6410d7137756       c2103589e99f9       10 days ago         Running             node-driver-registrar          0                   437b4ec6c4d5a
a72985dc02fd3       91b2502cca9dd       10 days ago         Running             yc-disk-csi-driver             0                   437b4ec6c4d5a
52430c9e87ee6       ab0f9cd91cf93       10 days ago         Running             ip-masq-agent                  0                   d9cf9093a905d
crictl stats
CONTAINER           CPU %               MEM                 DISK                INODES
0776bd9a1049c       0.02                4.592MB             45.06kB             11
52430c9e87ee6       0.00                11.08MB             28.67kB             8
52f7e322ee693       0.09                4.08MB              28.67kB             8
58608563ae1f3       0.01                18.7MB              32.77kB             10
5fe144bb15d93       0.25                195.4MB             241.7kB             53
76783773d8b55       0.31                19.34MB             40.96kB             10
93145e000e190       0.00                10.33MB             32.77kB             10
9c9e66a3275bd       0.03                24.3MB              32.77kB             10
9dfe97121d4e0       0.00                2.527MB             40.96kB             12
a72985dc02fd3       0.00                4.882MB             45.06kB             11
ab405f341fd4f       0.00                10.79MB             65.54kB             19
acd38fe8fc03d       0.01                3.564MB             36.86kB             11
b979627e609fe       0.00                5.411MB             36.86kB             11
bbeb1e41c0701       0.00                5.091MB             32.77kB             10
c6689fbac9d95       0.12                20.23MB             61.44kB             18
d6410d7137756       0.00                2.781MB             40.96kB             12
ebb8e863a3d37       0.15                7.709MB             49.15kB             15
ec53c21694bb6       0.01                3.588MB             36.86kB             11
ecf2e4a59b71c       0.05                17.3MB              32.77kB             10
crictl info
{
  "status": {
    "conditions": [
      {
        "type": "RuntimeReady",
        "status": true,
        "reason": "",
        "message": ""
      },
      {
        "type": "NetworkReady",
        "status": true,
        "reason": "",
        "message": ""
      }
    ]
  },
  "cniconfig": {
    "PluginDirs": [
      "/home/kubernetes/cni/bin"
    ],
    "PluginConfDir": "/etc/cni/net.d",
    "PluginMaxConfNum": 1,
    "Prefix": "eth",
    "Networks": [
      {
        "Config": {
          "Name": "cni-loopback",
          "CNIVersion": "0.3.1",
          "Plugins": [
            {
              "Network": {
                "type": "loopback",
                "ipam": {},
                "dns": {}
              },
              "Source": "{\"type\":\"loopback\"}"
            }
          ],
          "Source": "{\n\"cniVersion\": \"0.3.1\",\n\"name\": \"cni-loopback\",\n\"plugins\": [{\n  \"type\": \"loopback\"\n}]\n}"
        },
        "IFName": "lo"
      },
      {
        "Config": {
          "Name": "cilium",
          "CNIVersion": "0.3.1",
          "Plugins": [
            {
              "Network": {
                "cniVersion": "0.3.1",
                "name": "cilium",
                "type": "cilium-cni",
                "ipam": {},
                "dns": {}
              },
              "Source": "{\"cniVersion\":\"0.3.1\",\"enable-debug\":false,\"name\":\"cilium\",\"type\":\"cilium-cni\"}"
            }
          ],
          "Source": "{\"cniVersion\":\"0.3.1\",\"name\":\"cilium\",\"plugins\":[{\"cniVersion\":\"0.3.1\",\"enable-debug\":false,\"name\":\"cilium\",\"type\":\"cilium-cni\"}]}"
        },
        "IFName": "eth0"
      }
    ]
  },
  "config": {
    "containerd": {
      "snapshotter": "overlayfs",
      "defaultRuntimeName": "runc",
      "defaultRuntime": {
        "runtimeType": "",
        "runtimePath": "",
        "runtimeEngine": "",
        "PodAnnotations": null,
        "ContainerAnnotations": null,
        "runtimeRoot": "",
        "options": null,
        "privileged_without_host_devices": false,
        "baseRuntimeSpec": "",
        "cniConfDir": "",
        "cniMaxConfNum": 0
      },
      "untrustedWorkloadRuntime": {
        "runtimeType": "",
        "runtimePath": "",
        "runtimeEngine": "",
        "PodAnnotations": null,
        "ContainerAnnotations": null,
        "runtimeRoot": "",
        "options": null,
        "privileged_without_host_devices": false,
        "baseRuntimeSpec": "",
        "cniConfDir": "",
        "cniMaxConfNum": 0
      },
      "runtimes": {
        "runc": {
          "runtimeType": "io.containerd.runc.v2",
          "runtimePath": "",
          "runtimeEngine": "",
          "PodAnnotations": null,
          "ContainerAnnotations": null,
          "runtimeRoot": "",
          "options": {
            "BinaryName": "",
            "CriuImagePath": "",
            "CriuPath": "",
            "CriuWorkPath": "",
            "IoGid": 0,
            "IoUid": 0,
            "NoNewKeyring": false,
            "NoPivotRoot": false,
            "Root": "",
            "ShimCgroup": "",
            "SystemdCgroup": false
          },
          "privileged_without_host_devices": false,
          "baseRuntimeSpec": "",
          "cniConfDir": "",
          "cniMaxConfNum": 0
        }
      },
      "noPivot": false,
      "disableSnapshotAnnotations": true,
      "discardUnpackedLayers": false,
      "ignoreRdtNotEnabledErrors": false
    },
    "cni": {
      "binDir": "/home/kubernetes/cni/bin",
      "confDir": "/etc/cni/net.d",
      "maxConfNum": 1,
      "confTemplate": "",
      "ipPref": ""
    },
    "registry": {
      "configPath": "",
      "mirrors": null,
      "configs": null,
      "auths": null,
      "headers": null
    },
    "imageDecryption": {
      "keyModel": "node"
    },
    "disableTCPService": true,
    "streamServerAddress": "127.0.0.1",
    "streamServerPort": "0",
    "streamIdleTimeout": "4h0m0s",
    "enableSelinux": false,
    "selinuxCategoryRange": 1024,
    "sandboxImage": "",
    "statsCollectPeriod": 10,
    "systemdCgroup": false,
    "enableTLSStreaming": false,
    "x509KeyPairStreaming": {
      "tlsCertFile": "",
      "tlsKeyFile": ""
    },
    "maxContainerLogSize": 16384,
    "disableCgroup": false,
    "disableApparmor": false,
    "restrictOOMScoreAdj": false,
    "maxConcurrentDownloads": 3,
    "disableProcMount": false,
    "unsetSeccompProfile": "",
    "tolerateMissingHugetlbController": true,
    "disableHugetlbController": true,
    "device_ownership_from_security_context": false,
    "ignoreImageDefinedVolumes": false,
    "netnsMountsUnderStateDir": false,
    "enableUnprivilegedPorts": false,
    "enableUnprivilegedICMP": false,
    "containerdRootDir": "/var/lib/containerd",
    "containerdEndpoint": "/run/containerd/containerd.sock",
    "rootDir": "/var/lib/containerd/io.containerd.grpc.v1.cri",
    "stateDir": "/run/containerd/io.containerd.grpc.v1.cri"
  },
  "golang": "go1.17.13",
  "lastCNILoadStatus": "OK",
  "lastCNILoadStatus.default": "OK"
crictl version
Version:  0.1.0
RuntimeName:  containerd
RuntimeVersion:  1.6.7
RuntimeApiVersion:  v1alpha2
crictl pods
POD ID              CREATED             STATE               NAME                                       NAMESPACE           ATTEMPT             RUNTIME
cac496ddc4da6       8 minutes ago       NotReady            hubble-generate-certs-btfrp                kube-system         0                   (default)
3ff2b728b7bb5       10 hours ago        Ready               mypod                                      default             1                   (default)
315fb5a0e3d7e       4 days ago          Ready               cert-manager-webhook-785bb86798-65blx      cert-manager        0                   (default)
f4acc41ed52ce       4 days ago          Ready               cert-manager-6544c44c6b-9jxqh              cert-manager        0                   (default)
95d45c2828654       4 days ago          Ready               cert-manager-cainjector-5687864d5f-wvk95   cert-manager        0                   (default)
7f3beeed99f54       10 days ago         Ready               hubble-relay-987b4d4b4-vzjjm               kube-system         0                   (default)
46c7a28a5d697       10 days ago         Ready               metrics-server-75c6f8d8c-qgvxg             kube-system         0                   (default)
11735ffc744c9       10 days ago         Ready               coredns-786b4cc45f-hmv44                   kube-system         0                   (default)
e9f8f445b9763       10 days ago         Ready               npd-v0.8.0-pwl7g                           kube-system         0                   (default)
3639b1ff27d6b       10 days ago         Ready               kube-dns-autoscaler-5d9767598c-6ccmp       kube-system         0                   (default)
9cc1a85a78811       10 days ago         Ready               cilium-fbtvs                               kube-system         0                   (default)
437b4ec6c4d5a       10 days ago         Ready               yc-disk-csi-node-v2-dkq6h                  kube-system         0                   (default)
fe00b546386f9       10 days ago         Ready               cilium-operator-7545446c99-ch7mn           kube-system         0                   (default)
d9cf9093a905d       10 days ago         Ready               ip-masq-agent-b5cv7                        kube-system         0                   (default)

Полезные ссылки.

https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md