docker-拉本地图像以在Kubernetes中运行Pod

我有一个由Dockerfile创建的以下图像:

REPOSITORY   TAG      IMAGE ID       CREATED       SIZE 
ruby/lab     latest   f1903b1508cb   2 hours ago   729.6 MB

我有以下YAML文件:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ruby-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: ruby
    spec:
      containers:
      - name: ruby-app
        image: ruby/lab
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 4567

创建部署时,我在窗格中获得以下信息:

ruby-deployment-3830038651-sa4ii   0/1       ImagePullBackOff   0          7m
ruby-deployment-3830038651-u1tvc   0/1       ImagePullBackOff   0          7m

从下面的错误Failed to pull image "ruby/lab:latest": Error: image ruby/lab not found

 8m            2m              6       {kubelet minikube}      spec.containers{ruby}   Normal          Pulling         pulling image "ruby/lab:latest"
 8m            2m              6       {kubelet minikube}      spec.containers{ruby}   Warning         Failed          Failed to pull image "ruby/lab:latest": Error: image ruby/lab not found
 8m            2m              6       {kubelet minikube}                              Warning         FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "ruby" with ErrImagePull: "Error: image ruby/lab not found"

为此,在docker中真正有必要注册吗? 我只想在本地进行测试并将我的代码/存储库传递给朋友以进行测试

谢谢

CPB asked 2020-06-30T14:41:03Z
3个解决方案
68 votes

您可以通过运行将Docker客户端指向虚拟机的Docker守护程序

eval $(minikube docker-env)

然后,您可以正常使用kubectl构建映像并正常创建kubernetes资源。 确保你有

imagePullPolicy: IfNotPresent

在您的YAML或JSON规范中。

此外,还有一个标志可以将不安全的注册表传递给minikube VM。 但是,必须在初次创建计算机时指定它。

minikube start --insecure-registry

使用私有注册表时,您可能还需要阅读此内容[http://kubernetes.io/docs/user-guide/images/]

Matt Rickard answered 2020-06-30T14:41:39Z
21 votes

AFAIR minikube在VM中运行,因此它不会看到您在主机上本地构建的映像,而是... [https://github.com/kubernetes/minikube/blob/master/docs/reusing_the_docker_daemon中所述 .md],您可以使用eval $(minikube docker-env)来实际利用在minikube上运行的docker守护进程,然后在minikubes docker上构建映像,从而期望该映像可用于minikubes k8s引擎而无需从外部注册表中提取

Radek 'Goblin' Pieczonka answered 2020-06-30T14:42:00Z
0 votes

docker pull,在每个节点中手动拉所有图像要么运行DaemonSet提取所有图像

shenyan answered 2020-06-30T14:42:22Z
translate from https://stackoverflow.com:/questions/40144138/pull-a-local-image-to-run-a-pod-in-kubernetes