Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 896
Bunyk Avatar asked Apr 06 '19 13:04

Bunyk


1 Answers

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

like image 125
Bunyk Avatar answered Oct 22 '22 00:10

Bunyk