拉取本地镜像以在 Kubernetes 中运行 Pod [英] Pull a local image to run a pod in Kubernetes
问题描述
我有以下由 Dockerfile 创建的图像:
REPOSITORY TAG IMAGE ID 创建大小ruby/lab 最新的 f1903b1508cb 2 小时前 729.6 MB
我有以下 YAML 文件:
apiVersion: extensions/v1beta1种类:部署元数据:名称:ruby-部署规格:复制品:2模板:元数据:标签:应用程序:红宝石规格:容器:- 名称:ruby-app图片:红宝石/实验室imagePullPolicy: IfNotPresent端口:- 容器端口:4567
当我创建部署时,我在 pod 中获得了以下信息:
ruby-deployment-3830038651-sa4ii 0/1 ImagePullBackOff 0 7mruby-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 pull image "ruby/lab:latest"8m 2m 6 {kubelet minikube} spec.containers{ruby} 警告失败 无法拉取镜像ruby/lab:latest":错误:未找到镜像 ruby/lab8m 2m 6 {kubelet minikube} 警告 FailedSync 同步 pod 时出错,跳过:无法使用 ErrImagePull 为ruby"启动容器":错误:图像 ruby/lab 未找到"
真的有必要为此在 docker 中注册吗?我只想在本地进行测试并将我的代码/存储库传递给朋友以进行测试
谢谢
您可以通过运行
将您的 docker 客户端指向 VM 的 docker 守护进程eval $(minikube docker-env)
然后就可以正常构建镜像,正常使用kubectl创建kubernetes资源了.确保你有
imagePullPolicy: IfNotPresent
在您的 YAML 或 JSON 规范中.
此外,还有一个标志可以将不安全的注册表传递给 minikube 虚拟机.但是,这必须在您第一次创建机器时指定.
minikube start --insecure-registry
您可能还想在使用私有注册表时阅读此内容http://kubernetes.io/docs/user-guide/images/>
I have the following image created by a Dockerfile:
REPOSITORY TAG IMAGE ID CREATED SIZE
ruby/lab latest f1903b1508cb 2 hours ago 729.6 MB
And I have my following YAML file:
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
When I create the deployment I got the following info in the pods:
ruby-deployment-3830038651-sa4ii 0/1 ImagePullBackOff 0 7m
ruby-deployment-3830038651-u1tvc 0/1 ImagePullBackOff 0 7m
And the error Failed to pull image "ruby/lab:latest": Error: image ruby/lab not found
from below:
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"
Is really necessary to have registry in docker for this? I just want to make test locally and pass my code/repo to a friend for testing purposes
Thanks
You can point your docker client to the VM's docker daemon by running
eval $(minikube docker-env)
Then you can build your image normally and create your kubernetes resources normally using kubectl. Make sure that you have
imagePullPolicy: IfNotPresent
in your YAML or JSON specs.
Additionally, there is a flag to pass in insecure registries to the minikube VM. However, this must be specified the first time you create the machine.
minikube start --insecure-registry
You may also want to read this when using a private registry http://kubernetes.io/docs/user-guide/images/
这篇关于拉取本地镜像以在 Kubernetes 中运行 Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!