gpt4 book ai didi

docker - 127.0.0.1 :5000: getsockopt: connection refused in Minikube

转载 作者:行者123 更新时间:2023-12-02 07:12:09 41 4
gpt4 key购买 nike

在本地 Ubuntu 工作站上使用 minikube 和 docker,我在 Minikube Web UI 中收到以下错误:

Failed to pull image "localhost:5000/samples/myserver:snapshot-180717-213718-0199": rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: getsockopt: connection refused

在我创建以下部署配置后:

kubectl apply -f hello-world-deployment.yaml

hello-world-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 1
template:
metadata:
labels:
app: hello-world
tier: backend
spec:
containers:
- name: hello-world
image: localhost:5000/samples/myserver:snapshot-180717-213718-0199
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
ports:
- containerPort: 8080

以及 docker 镜像的输出:

REPOSITORY                                 TAG                           IMAGE ID            CREATED             SIZE
samples/myserver latest aa0a1388cd88 About an hour ago 435MB
samples/myserver snapshot-180717-213718-0199 aa0a1388cd88 About an hour ago 435MB
k8s.gcr.io/kube-proxy-amd64 v1.10.0 bfc21aadc7d3 3 months ago 97MB

基于本指南: How to use local docker images with Minikube?

我也跑过:

eval $(minikube docker-env)

并基于此:

https://github.com/docker/for-win/issues/624

我添加了:

    "InsecureRegistry": [
"localhost:5000",
"127.0.0.1:5000"
],

/etc/docker/daemon.json

对于我缺少什么来让镜像在 minikube 中工作有什么建议吗?

我已按照以下答案中的步骤进行操作,但是当我到达此步骤时:

$ kubectl port-forward --namespace kube-system $(kubectl get po -n kube-system | grep kube-registry-v0 | awk '{print $1;}') 5000:5000

它就像这样挂起:

$ kubectl port-forward --namespace kube-system $(kubectl get po -n kube-system | grep kube-registry-v0 | awk '{print $1;}') 5000:5000
Forwarding from 127.0.0.1:5000 -> 5000
Forwarding from [::1]:5000 -> 5000

创建部署配置后,我在 minikube 仪表板中遇到了相同的错误。

根据 BMitch 的回答,我现在尝试创建一个本地 docker 存储库并将图像推送到其中:

$ docker run -d -p 5000:5000 --restart always --name registry registry:2
$ docker pull ubuntu
$ docker tag ubuntu localhost:5000/ubuntu:v1
$ docker push localhost:5000/ubuntu:v1

接下来,当我执行 docker 镜像时,我得到:

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 74f8760a2a8b 4 days ago 82.4MB
localhost:5000/ubuntu v1 74f8760a2a8b 4 days ago 82.4MB

然后我将部署配置 hello-world-deployment.yaml 更新为:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 1
template:
metadata:
labels:
app: hello-world
tier: backend
spec:
containers:
- name: hello-world
image: localhost:5000/ubuntu:v1
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
ports:
- containerPort: 8080

kubectl create -f hello-world-deployment.yaml

但是在 Minikube 中我仍然遇到类似的错误:

 Failed to pull image "localhost:5000/ubuntu:v1": rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: getsockopt: connection refused 

看来 Minikube 不允许查看我刚刚创建的本地注册表?

最佳答案

看起来您遇到了计算机上的localhostminikube VM上下文中使用的localhost问题。要使注册表正常工作,您必须设置额外的端口转发。

如果您的minikube由于多次尝试修复注册表问题,目前安装已损坏,我建议重新启动 minikube 环境:

minikube stop && minikube delete && rm -fr $HOME/.minikube &&  minikube start

接下来,获取 kube 注册表 yaml 文件:

curl -O https://gist.githubusercontent.com/coco98/b750b3debc6d517308596c248daf3bb1/raw/6efc11eb8c2dce167ba0a5e557833cc4ff38fa7c/kube-registry.yaml

然后,将其应用到 minikube 上:

kubectl create -f kube-registry.yaml

测试 minikube VM 内的注册表是否有效:

minikube ssh && curl localhost:5000

在 Ubuntu 上,转发端口以到达端口 5000 处的注册表:

kubectl port-forward --namespace kube-system $(kubectl get po -n kube-system | grep kube-registry-v0 | awk '{print $1;}') 5000:5000

如果您想从您的计算机共享您的私有(private)注册表,您可能会对 sharing local registry for minikube 感兴趣。博客条目。

关于docker - 127.0.0.1 :5000: getsockopt: connection refused in Minikube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51390161/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com