shell命令编--获取kubeflow中所有pod的镜像名
程序员文章站
2024-03-11 10:49:55
...
shell命令编–获取kubeflow中所有pod的镜像名
需求: 将墙外镜像库中kubeflow应用的镜像拉取到本地的私有镜像库,供无法连接外网的k8s集群使用
过程:
- docker pull kubeflow所有镜像
- docker tag kubeflow所有镜像
- docker push kubeflow所有镜像
思考:
- 如果将整个复杂的过程转化成三条命令解决?
获取kubeflow所有镜像版本
- 获取kubeflow所有pod的信息
kubectl get po -n kubeflow
[email protected]:~/shiyu/kuberflow-istio$ kubectl get po -n kubeflow
NAME READY STATUS RESTARTS AGE
admission-webhook-bootstrap-stateful-set-0 0/1 ContainerCreating 0 23m
admission-webhook-deployment-78969d856-965lp 0/1 ContainerCreating 0 48m
application-controller-stateful-set-0 0/1 RunContainerError 0 76m
argo-ui-55b859f7d7-q5dgm 1/1 Running 1 76m
centraldashboard-7f68f6bf7b-jst2d 1/1 Running 1 76m
jupyter-web-app-deployment-5b56748d57-99h4f 0/1 ContainerCreating 0 48m
katib-controller-67db57fd77-xjt2b 0/1 ContainerCreating 0 48m
katib-db-84bf8c5dc5-ndlxp 0/1 Pending 0 76m
katib-manager-7b9d5b77b8-n2wlf 0/1 ContainerCreating 0 48m
katib-ui-7d54f74bd5-d8zhd 0/1 ContainerCreating 0 48m
kfserving-controller-manager-0 0/2 ContainerCreating 0 48m
metacontroller-0 0/1 RunContainerError 0 76m
metadata-db-7fd6c666dd-hmrfn 0/1 Pending 0 76m
metadata-deployment-7648dc5c96-fhcfc 0/1 ContainerCreating 0 48m
metadata-envoy-deployment-d585c9744-m88gb 0/1 ContainerCreating 0 48m
metadata-grpc-deployment-7ddc8879bf-lswjn 0/1 ContainerCreating 0 48m
metadata-ui-6dcdc56bbd-7qxql 0/1 ContainerCreating 0 48m
minio-6f48db9cc4-qprzf 0/1 Pending 0 76m
ml-pipeline-844645fd-5lvkq 0/1 ContainerCreating 0 48m
ml-pipeline-ml-pipeline-visualizationserver-865894f5f7-f5fnr 0/1 ContainerCreating 0 48m
ml-pipeline-persistenceagent-66f89b56d9-f7w65 0/1 ContainerCreating 0 48m
ml-pipeline-scheduledworkflow-57445ddf88-klrbd 0/1 ContainerCreating 0 48m
ml-pipeline-ui-5c64b6c666-6gv84 0/1 ContainerCreating 0 48m
ml-pipeline-viewer-controller-deployment-7cc8d77468-htv6r 0/1 ContainerCreating 0 48m
mysql-749f87bff5-crkpn 0/1 Pending 0 75m
notebook-controller-deployment-84d8d8d96f-cqsjn 0/1 ContainerCreating 0 48m
profiles-deployment-59c97f99b7-j5pwt 0/2 ContainerCreating 0 48m
pytorch-operator-dfb5c4c88-7dzq6 0/1 ContainerCreating 0 48m
seldon-operator-controller-manager-0 0/1 ContainerCreating 0 48m
spartakus-volunteer-69868fb9cd-f4q48 0/1 ContainerCreating 0 48m
tensorboard-6544748d94-j7kzz 0/1 ContainerCreating 0 48m
tf-job-operator-5d7dbd94c7-hsxsj 0/1 ContainerCreating 0 48m
workflow-controller-676484d796-2bl59 1/1 Running 1 76m
- 通过grep,过滤出image相关信息
kubectl get po -n kubeflow -o yaml |grep image:
[email protected]:~/shiyu/kuberflow-istio$ kubectl get po -n kubeflow -o yaml |grep image:
image: gcr.io/kubeflow-images-public/ingress-setup:latest
- image: gcr.io/kubeflow-images-public/ingress-setup:latest
- image: gcr.io/kubeflow-images-public/admission-webhook:v20190520-v0-139-gcee39dbc-dirty-0d8f4c
- image: gcr.io/kubeflow-images-public/admission-webhook:v20190520-v0-139-gcee39dbc-dirty-0d8f4c
image: gcr.io/kubeflow-images-public/kubernetes-sigs/application:1.0-beta
image: gcr.io/kubeflow-images-public/kubernetes-sigs/application:1.0-beta
image: argoproj/argoui:v2.3.0
image: argoproj/argoui:v2.3.0
image: gcr.io/kubeflow-images-public/[email protected]:4299297b8390599854aa8f77e9eb717db684b32ca9a94a0ab0e73f3f73e5d8b5
image: sha256:8fb2e7d74d1e52f9fb1a6e4b75a69c569fa02b93aa2db74aa6209fbedc43238b
image: gcr.io/kubeflow-images-public/jupyter-web-app:9419d4d
- image: gcr.io/kubeflow-images-public/jupyter-web-app:9419d4d
image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-controller:v0.7.0
- image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-controller:v0.7.0
image: mysql:8
image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-manager:v0.7.0
- image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-manager:v0.7.0
image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-ui:v0.7.0
- image: gcr.io/kubeflow-images-public/katib/v1alpha3/katib-ui:v0.7.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.4.0
image: gcr.io/kfserving/kfserving-controller:0.2.2
- image: gcr.io/kubebuilder/kube-rbac-proxy:v0.4.0
- image: gcr.io/kfserving/kfserving-controller:0.2.2
image: metacontroller/metacontroller:v0.3.0
image: metacontroller/metacontroller:v0.3.0
image: mysql:8.0.3
image: gcr.io/kubeflow-images-public/metadata:v0.1.11
- image: gcr.io/kubeflow-images-public/metadata:v0.1.11
- image: gcr.io/ml-pipeline/envoy:metadata-grpc
- image: gcr.io/ml-pipeline/envoy:metadata-grpc
image: gcr.io/tfx-oss-public/ml_metadata_store_server:0.15.1
- image: gcr.io/tfx-oss-public/ml_metadata_store_server:0.15.1
- image: gcr.io/kubeflow-images-public/metadata-frontend:v0.1.8
- image: gcr.io/kubeflow-images-public/metadata-frontend:v0.1.8
image: minio/minio:RELEASE.2018-02-09T22-40-05Z
image: gcr.io/ml-pipeline/api-server:0.1.31
- image: gcr.io/ml-pipeline/api-server:0.1.31
- image: gcr.io/ml-pipeline/visualization-server:0.1.27
- image: gcr.io/ml-pipeline/visualization-server:0.1.27
image: gcr.io/ml-pipeline/persistenceagent:0.1.31
- image: gcr.io/ml-pipeline/persistenceagent:0.1.31
image: gcr.io/ml-pipeline/scheduledworkflow:0.1.31
- image: gcr.io/ml-pipeline/scheduledworkflow:0.1.31
- image: gcr.io/ml-pipeline/frontend:0.1.31
- image: gcr.io/ml-pipeline/frontend:0.1.31
image: gcr.io/ml-pipeline/viewer-crd-controller:0.1.31
- image: gcr.io/ml-pipeline/viewer-crd-controller:0.1.31
image: mysql:5.6
image: gcr.io/kubeflow-images-public/[email protected]:6490f737000bd1d2520ac4b8cbde2b09749cdb291b1967ddda95d05131db49db
- image: gcr.io/kubeflow-images-public/[email protected]:6490f737000bd1d2520ac4b8cbde2b09749cdb291b1967ddda95d05131db49db
image: gcr.io/kubeflow-images-public/[email protected]:e601b2226e534a4f8e0722cfc44ae4a919a90265c4c6c9e7a7a55fcb57032f25
image: gcr.io/kubeflow-images-public/[email protected]:3b0d4be7e59a3fa5ed1d80dccc832312caa94f3b2d36682524d3afc4e45164f0
- image: gcr.io/kubeflow-images-public/[email protected]:3b0d4be7e59a3fa5ed1d80dccc832312caa94f3b2d36682524d3afc4e45164f0
- image: gcr.io/kubeflow-images-public/[email protected]:e601b2226e534a4f8e0722cfc44ae4a919a90265c4c6c9e7a7a55fcb57032f25
image: gcr.io/kubeflow-images-public/pytorch-operator:v0.7.0
- image: gcr.io/kubeflow-images-public/pytorch-operator:v0.7.0
image: docker.io/seldonio/seldon-core-operator:0.4.1
- image: docker.io/seldonio/seldon-core-operator:0.4.1
image: gcr.io/google_containers/spartakus-amd64:v1.1.0
- image: gcr.io/google_containers/spartakus-amd64:v1.1.0
image: tensorflow/tensorflow:1.8.0
- image: tensorflow/tensorflow:1.8.0
image: gcr.io/kubeflow-images-public/tf_operator:v0.7.0
- image: gcr.io/kubeflow-images-public/tf_operator:v0.7.0
image: argoproj/workflow-controller:v2.3.0
image: argoproj/workflow-controller:v2.3.0
- 通过cut命令获取需要的镜像名:tag,
kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14-
[email protected]:~/shiyu/kuberflow-istio$ kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14-
gcr.io/kubeflow-images-public/ingress-setup:latest
gcr.io/kubeflow-images-public/ingress-setup:latest
gcr.io/kubeflow-images-public/admission-webhook:v20190520-v0-139-gcee39dbc-dirty-0d8f4c
gcr.io/kubeflow-images-public/admission-webhook:v20190520-v0-139-gcee39dbc-dirty-0d8f4c
gcr.io/kubeflow-images-public/kubernetes-sigs/application:1.0-beta
gcr.io/kubeflow-images-public/kubernetes-sigs/application:1.0-beta
argoproj/argoui:v2.3.0
argoproj/argoui:v2.3.0
gcr.io/kubeflow-images-public/[email protected]:4299297b8390599854aa8f77e9eb717db684b32ca9a94a0ab0e73f3f73e5d8b5
sha256:8fb2e7d74d1e52f9fb1a6e4b75a69c569fa02b93aa2db74aa6209fbedc43238b
gcr.io/kubeflow-images-public/jupyter-web-app:9419d4d
gcr.io/kubeflow-images-public/jupyter-web-app:9419d4d
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-controller:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-controller:v0.7.0
mysql:8
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-manager:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-manager:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-ui:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-ui:v0.7.0
gcr.io/kubebuilder/kube-rbac-proxy:v0.4.0
gcr.io/kfserving/kfserving-controller:0.2.2
gcr.io/kubebuilder/kube-rbac-proxy:v0.4.0
gcr.io/kfserving/kfserving-controller:0.2.2
metacontroller/metacontroller:v0.3.0
metacontroller/metacontroller:v0.3.0
mysql:8.0.3
gcr.io/kubeflow-images-public/metadata:v0.1.11
gcr.io/kubeflow-images-public/metadata:v0.1.11
gcr.io/ml-pipeline/envoy:metadata-grpc
gcr.io/ml-pipeline/envoy:metadata-grpc
gcr.io/tfx-oss-public/ml_metadata_store_server:0.15.1
gcr.io/tfx-oss-public/ml_metadata_store_server:0.15.1
gcr.io/kubeflow-images-public/metadata-frontend:v0.1.8
gcr.io/kubeflow-images-public/metadata-frontend:v0.1.8
minio/minio:RELEASE.2018-02-09T22-40-05Z
gcr.io/ml-pipeline/api-server:0.1.31
gcr.io/ml-pipeline/api-server:0.1.31
gcr.io/ml-pipeline/visualization-server:0.1.27
gcr.io/ml-pipeline/visualization-server:0.1.27
gcr.io/ml-pipeline/persistenceagent:0.1.31
gcr.io/ml-pipeline/persistenceagent:0.1.31
gcr.io/ml-pipeline/scheduledworkflow:0.1.31
gcr.io/ml-pipeline/scheduledworkflow:0.1.31
gcr.io/ml-pipeline/frontend:0.1.31
gcr.io/ml-pipeline/frontend:0.1.31
gcr.io/ml-pipeline/viewer-crd-controller:0.1.31
gcr.io/ml-pipeline/viewer-crd-controller:0.1.31
mysql:5.6
gcr.io/kubeflow-images-public/[email protected]:6490f737000bd1d2520ac4b8cbde2b09749cdb291b1967ddda95d05131db49db
gcr.io/kubeflow-images-public/[email protected]:6490f737000bd1d2520ac4b8cbde2b09749cdb291b1967ddda95d05131db49db
gcr.io/kubeflow-images-public/[email protected]:e601b2226e534a4f8e0722cfc44ae4a919a90265c4c6c9e7a7a55fcb57032f25
gcr.io/kubeflow-images-public/[email protected]:3b0d4be7e59a3fa5ed1d80dccc832312caa94f3b2d36682524d3afc4e45164f0
gcr.io/kubeflow-images-public/[email protected]:3b0d4be7e59a3fa5ed1d80dccc832312caa94f3b2d36682524d3afc4e45164f0
gcr.io/kubeflow-images-public/[email protected]:e601b2226e534a4f8e0722cfc44ae4a919a90265c4c6c9e7a7a55fcb57032f25
gcr.io/kubeflow-images-public/pytorch-operator:v0.7.0
gcr.io/kubeflow-images-public/pytorch-operator:v0.7.0
docker.io/seldonio/seldon-core-operator:0.4.1
docker.io/seldonio/seldon-core-operator:0.4.1
gcr.io/google_containers/spartakus-amd64:v1.1.0
gcr.io/google_containers/spartakus-amd64:v1.1.0
tensorflow/tensorflow:1.8.0
tensorflow/tensorflow:1.8.0
gcr.io/kubeflow-images-public/tf_operator:v0.7.0
gcr.io/kubeflow-images-public/tf_operator:v0.7.0
argoproj/workflow-controller:v2.3.0
argoproj/workflow-controller:v2.3.0
- 去重:
kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14- | sort | sed '$!N; /^\(.*\)\n\1$/!P; D'
[email protected]:~/shiyu/kuberflow-istio$ kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14- | sort | sed '$!N; /^\(.*\)\n\1$/!P; D'
argoproj/argoui:v2.3.0
argoproj/workflow-controller:v2.3.0
docker.io/seldonio/seldon-core-operator:0.4.1
gcr.io/google_containers/spartakus-amd64:v1.1.0
gcr.io/kfserving/kfserving-controller:0.2.2
gcr.io/kubebuilder/kube-rbac-proxy:v0.4.0
gcr.io/kubeflow-images-public/admission-webhook:v20190520-v0-139-gcee39dbc-dirty-0d8f4c
gcr.io/kubeflow-images-public/[email protected]:4299297b8390599854aa8f77e9eb717db684b32ca9a94a0ab0e73f3f73e5d8b5
gcr.io/kubeflow-images-public/ingress-setup:latest
gcr.io/kubeflow-images-public/jupyter-web-app:9419d4d
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-controller:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-manager:v0.7.0
gcr.io/kubeflow-images-public/katib/v1alpha3/katib-ui:v0.7.0
gcr.io/kubeflow-images-public/[email protected]:3b0d4be7e59a3fa5ed1d80dccc832312caa94f3b2d36682524d3afc4e45164f0
gcr.io/kubeflow-images-public/kubernetes-sigs/application:1.0-beta
gcr.io/kubeflow-images-public/metadata-frontend:v0.1.8
gcr.io/kubeflow-images-public/metadata:v0.1.11
gcr.io/kubeflow-images-public/[email protected]:6490f737000bd1d2520ac4b8cbde2b09749cdb291b1967ddda95d05131db49db
gcr.io/kubeflow-images-public/[email protected]:e601b2226e534a4f8e0722cfc44ae4a919a90265c4c6c9e7a7a55fcb57032f25
gcr.io/kubeflow-images-public/pytorch-operator:v0.7.0
gcr.io/kubeflow-images-public/tf_operator:v0.7.0
gcr.io/ml-pipeline/api-server:0.1.31
gcr.io/ml-pipeline/envoy:metadata-grpc
gcr.io/ml-pipeline/frontend:0.1.31
gcr.io/ml-pipeline/persistenceagent:0.1.31
gcr.io/ml-pipeline/scheduledworkflow:0.1.31
gcr.io/ml-pipeline/viewer-crd-controller:0.1.31
gcr.io/ml-pipeline/visualization-server:0.1.27
gcr.io/tfx-oss-public/ml_metadata_store_server:0.15.1
metacontroller/metacontroller:v0.3.0
minio/minio:RELEASE.2018-02-09T22-40-05Z
mysql:5.6
mysql:8
mysql:8.0.3
sha256:8fb2e7d74d1e52f9fb1a6e4b75a69c569fa02b93aa2db74aa6209fbedc43238b
tensorflow/tensorflow:1.8.0
拉取kubeflow所有应用的镜像
for i in $(kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14- | sort | sed '$!N; /^\(.*\)\n\1$/!P; D'); do docker pull $i;done
[email protected]:~/shiyu/kuberflow-istio$ for i in $(kubectl get po -n kubeflow -o yaml |grep image:| cut -c 14- | sort | sed '$!N; /^\(.*\)\n\1$/!P; D'); do docker pull $i;done
v2.3.0: Pulling from argoproj/argoui
Digest: sha256:5e435ef40cbe4ad32ccaac16a1fa1679342b87a8d4db5715dec5290b74841c0c
Status: Image is up to date for argoproj/argoui:v2.3.0
v2.3.0: Pulling from argoproj/workflow-controller
Digest: sha256:5366ed9a8520df09cea8abe55823794ed697306884b4a1268e96459c2cf52fe6
Status: Image is up to date for argoproj/workflow-controller:v2.3.0
0.4.1: Pulling from seldonio/seldon-core-operator
Digest: sha256:ee1417d98557dbd307f80b62646a8b2cc0f5b9317388aca8dfb07c6ed370a6b9
Status: Image is up to date for seldonio/seldon-core-operator:0.4.1
...
其中所用命令介绍
- grep
-
|grep image:
,过滤出包含image字符串的行
-
- cut
-
cut -c 14-
,按字符流切割字符串,从每行的第14个字符开始到行尾为止
-
- sort + sed
-
sort | sed '$!N; /^\(.*\)\n\1$/!P; D'
, 排序和sed去重
-
剩下的步骤待补充
。。。
总结
shell命令用的好可以节省掉大部分的人力时间,但shell命令博大精深,只有在不断的尝试中慢慢前行。
上述过程只是本人的一种实现方案在执行的性能没有过多的考虑,若感兴趣可私聊共同讨论,写的不对之处请见谅,亦可私聊知会本人改正之。