我是 kubernetes 的新手。最近成功用在线服务器管理kubernetes。但是,当我移动到隔离区域(离线服务器)时,我无法部署 kubectl 图像。但是我所有的环境都运行良好,我陷入了困境。不同的只是互联网连接。
目前,我无法在离线服务器上部署 kubernetes dashboard 和一些镜像。我在离线服务器上的 kubectl 命令示例(我是在在线服务器上下载的 tar 文件):
# docker load < nginx.tar
# kubectl create deployment test-nginx --image=nginx
# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default test-nginx-7d97ffc85d-2s4lh 0/1 ImagePullBackOff 0 50s
kube-system coredns-6955765f44-2s54f 1/1 Running 1 26h
kube-system coredns-6955765f44-wmtq9 1/1 Running 1 26h
kube-system etcd-devkubeapp01 1/1 Running 1 26h
kube-system kube-apiserver-devkubeapp01 1/1 Running 1 26h
kube-system kube-controller-manager-devkubeapp01 1/1 Running 1 26h
kube-system kube-flannel-ds-amd64-czn8z 1/1 Running 0 26h
kube-system kube-flannel-ds-amd64-d58x4 1/1 Running 0 26h
kube-system kube-flannel-ds-amd64-z9w9x 1/1 Running 0 26h
kube-system kube-proxy-9wxj2 1/1 Running 0 26h
kube-system kube-proxy-mr76b 1/1 Running 1 26h
kube-system kube-proxy-w5pvm 1/1 Running 0 26h
kube-system kube-scheduler-devkubeapp01 1/1 Running 1 26h
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
devkubeapp01 Ready master 26h v1.17.2
devkubeapp02 Ready minion1 26h v1.17.2
devkubeapp03 Ready minion2 25h v1.17.2
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 5ad3bd0e67a9 6 days ago 127MB
k8s.gcr.io/kube-proxy v1.17.2 cba2a99699bd 10 days ago 116MB
k8s.gcr.io/kube-apiserver v1.17.2 41ef50a5f06a 10 days ago 171MB
k8s.gcr.io/kube-controller-manager v1.17.2 da5fd66c4068 10 days ago 161MB
k8s.gcr.io/kube-scheduler v1.17.2 f52d4c527ef2 10 days ago 94.4MB
k8s.gcr.io/coredns 1.6.5 70f311871ae1 2 months ago 41.6MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 3 months ago 288MB
quay.io/coreos/flannel v0.11.0-amd64 ff281650a721 12 months ago 52.6MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 2 years ago 742kB
我的 Pod 无法正常运行,所以状态 CreatingContainer 变成了 ImagePullBackOff(我在断开互联网连接时在在线服务器中尝试,状态相同 => ImagePullBackOff)。任何人都可以帮助解决这个问题吗? kubernetes是否支持离线环境部署镜像?
谢谢。
最佳答案
正如我之前的评论中所述:
I suspect that your
imagePullPolicy
might be misconfigured.
并通过您提供的日志进一步证明:
Error from server (BadRequest): container "nginx" in pod "test-nginx-7d97ffc85d-2s4lh" is waiting to start: trying and failing to pull image
问题在于 imagePullPolicy
configuration .
如 official documentation 中所述:
Pre-pulled Images
By default, the kubelet will try to pull each image from the specified registry. However, if the
imagePullPolicy
property of the container is set toIfNotPresent
orNever
, then a local image is used (preferentially or exclusively, respectively).If you want to rely on pre-pulled images as a substitute for registry authentication, you must ensure all nodes in the cluster have the same pre-pulled images.
基本上,正如@Eduardo 已经提到的,您需要确保所有节点上都有相同的图像,并且您的 imagePullPolicy
已正确配置。
但是,要确保容器始终使用相同版本的图像,您可以指定其 digest ,例如 sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2
。摘要唯一标识图像的特定版本,因此除非您更改摘要值,否则 Kubernetes 永远不会更新它。
通过这种方式,您可以类似地避免将来出现问题,因为在这种情况下,在整个范围内保持完全相同版本的图像集群是最大的陷阱。
我希望这有助于扩展之前的答案(这是正确的),并从一开始就证明我的观点。
关于docker - 有没有一些方法可以离线管理 Kubernetes 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59947579/