如何配置kubernetes(microk8s)以使用本地docker镜像? [英] How to configure kubernetes (microk8s) to use local docker images?

查看:1021
本文介绍了如何配置kubernetes(microk8s)以使用本地docker镜像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在本地构建docker映像:

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 可以,但是后来我豆荚状态如下:

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

在此之前是 ErrImagePull 。所以,我的问题是,如何告诉它使用本地docker映像?我在互联网上的某个地方读到,我需要使用 microk8s.docker 构建映像,但它似乎要删除

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.

推荐答案

找到了有关如何使用私有注册表的文档: https://microk8s.io/docs/working

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

首先需要启用它:

microk8s.enable registry

然后将图像推送到注册表:

Then images pushed to registry:

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

配置 image:后端需要替换为 image:localhost:32000 / backend

这篇关于如何配置kubernetes(microk8s)以使用本地docker镜像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆