How to configure kubernetes (microk8s) to use local docker images?

浪子不回头ぞ 提交于 2019-12-11 03:42:50

问题


I've build docker image locally:

docker build -t backend -f backend.docker

Now I want to create deployment with it:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-deployment
spec:
  selector:
    matchLabels:
      tier: backend
  replicas: 2
  template:
    metadata:
      labels:
        tier: backend
    spec:
      containers:
      - name: backend
        image: backend
        imagePullPolicy: IfNotPresent # This should be by default so
        ports:
        - containerPort: 80

kubectl apply -f file_provided_above.yaml works, but then I have following pods statuses:

$ kubectl get pods
NAME                                   READY   STATUS             RESTARTS   AGE
backend-deployment-66cff7d4c6-gwbzf    0/1     ImagePullBackOff   0          18s

Before that it was ErrImagePull. So, my question is, how to tell it to use local docker images? Somewhere on the internet I read that I need to build images using microk8s.docker but it seems to be removed.


回答1:


Found docs on how to use private registry: https://microk8s.io/docs/working

First it needs to be enabled:

microk8s.enable registry

Then images pushed to registry:

docker tag backend localhost:32000/backend
docker push localhost:32000/backend

And then in above config image: backend needs to be replaced with image: localhost:32000/backend



来源:https://stackoverflow.com/questions/55549522/how-to-configure-kubernetes-microk8s-to-use-local-docker-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!