Is there some ways to manage Kubernetes image offline?

1/28/2020

I'm new to kubernetes. Recently, I was successfull to manage kubernetes with online server. But, when I move to isolated area (offline server) I can't deploy kubectl image. But all of my environment are running well and I got stuck in this. The different just internet connection.

Currently, I can't deploy kubernetes dashboard and some images in offline server. This example of my kubectl command in offline server (I was downloaded the tar file in online server) :

# 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

My Pod cant running well, so the status CreatingContainer turn into ImagePullBackOff (I was try in online server when I disconnected the Internet the status is same => ImagePullBackOff). Anyone can help to solve this ? Does kubernetes support offline environment to deploy the image ?

Thanks.

-- amsalmaestro
docker
kubernetes
offline

2 Answers

1/29/2020

As already stated in my previous comment:

I suspect that your imagePullPolicy might be misconfigured.

and further proven by the logs you have provided:

Error from server (BadRequest): container "nginx" in pod "test-nginx-7d97ffc85d-2s4lh" is waiting to start: trying and failing to pull image

the problem lays within the imagePullPolicy configuration.

As stated in the 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 to IfNotPresent or Never, 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.

So basically as already mentioned by @Eduardo you need to make sure that you have the same images on all nodes and your imagePullPolicy is correctly configured.

However, make sure the container always uses the same version of the image, you can specify its digest, for example sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2. The digest uniquely identifies a specific version of the image, so it is never updated by Kubernetes unless you change the digest value.

This way you would similar avoid issues in the future as keeping the exact same version of the image cluster wide is the biggest trap in this scenario.

I hope this helps and expands on the previous answer (which is correct) as well as proves my point from the very beginning.

-- OhHiMark
Source: StackOverflow

1/28/2020

Using an offline environment, you will need to pre-load the docker images on all your nodes and make sure to use the proper imagePullPolicy to prevent Kubernetes from downloading container images.

You need to:

  1. docker load < nginx.tar in all nodes
  2. Make sure the deployment is using imagePullPolicy with value IfNotPresent or Never (the default value is Always, which might be your problem).
-- Eduardo Baitello
Source: StackOverflow