Pol*_*ase 2 kubernetes kubectl
在 Kubernetes 文档列出集群中运行的所有容器映像中,我们可以通过以下方式列出所有容器:
kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
Run Code Online (Sandbox Code Playgroud)
下面是一个输出示例:
1 cdkbot/addon-resizer-amd64:1.8.1
1 cdkbot/hostpath-provisioner-amd64:1.0.0
1 cdkbot/registry-amd64:2.6
1 coredns/coredns:1.6.6
1 docker.io/cdkbot/addon-resizer-amd64:1.8.1
1 docker.io/cdkbot/hostpath-provisioner-amd64:1.0.0
1 docker.io/cdkbot/registry-amd64:2.6
1 docker.io/coredns/coredns:1.6.6
1 docker.io/grafana/grafana:6.4.3
2 docker.io/istio/citadel:1.5.1
2 docker.io/istio/examples-bookinfo-details-v1:1.15.0
2 docker.io/istio/examples-bookinfo-productpage-v1:1.15.0
2 docker.io/istio/examples-bookinfo-ratings-v1:1.15.0
2 docker.io/istio/examples-bookinfo-reviews-v1:1.15.0
2 docker.io/istio/examples-bookinfo-reviews-v2:1.15.0
2 docker.io/istio/examples-bookinfo-reviews-v3:1.15.0
2 docker.io/istio/galley:1.5.1
4 docker.io/istio/kubectl:1.5.1
4 docker.io/istio/mixer:1.5.1
2 docker.io/istio/pilot:1.5.1
34 docker.io/istio/proxyv2:1.5.1
2 docker.io/istio/sidecar_injector:1.5.1
2 docker.io/jaegertracing/all-in-one:1.16
1 docker.io/kubernetesui/dashboard:v2.0.0
1 docker.io/kubernetesui/metrics-scraper:v1.0.4
2 docker.io/library/nginx:latest
2 docker.io/prom/prometheus:v2.12.0
1 docker.io/radial/busyboxplus:curl
1 grafana/grafana:6.4.3
2 k8s.gcr.io/metrics-server-amd64:v0.2.1
1 kubernetesui/dashboard:v2.0.0
1 kubernetesui/metrics-scraper:v1.0.4
2 nginx
2 quay.io/kiali/kiali:v1.9
1 radial/busyboxplus:curl
Run Code Online (Sandbox Code Playgroud)
不幸的是,泊坞窗图像的大小丢失了。有没有办法获取容器图像大小?很像docker image ls
。为方便起见,复制此示例的输出:
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest 3556258649b2 7 days ago 64.2 MB
docker.io/alpine latest b7b28af77ffe 2 weeks ago 5.58 MB
docker.io/centos latest 9f38484d220f 4 months ago 202 MB
docker.io/hello-world latest fce289e99eb9 7 months ago 1.84 kB
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您拥有正确的权限,请获取节点而不是 Pod。
kubectl get nodes -o json | jq '.items[].status.images[] | .names[1], .sizeBytes'
Run Code Online (Sandbox Code Playgroud)
在我的 k8s 系统上 kubectl 描述 pod ABC 不显示图像大小,但您可以创建一个脚本:
总而言之,它看起来像这样:
docker image ls `kubectl get pod YOUR_POD_NAME_GOES_HERE -o jsonpath='{.spec.containers[0].image}'` --format='{{println .Size}}'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4119 次 |
最近记录: |