gpt4 book ai didi

kubernetes - Minikube无法使用Yaml公开服务

转载 作者:行者123 更新时间:2023-12-02 11:45:27 25 4
gpt4 key购买 nike

尝试运行本地注册表。我有以下配置:

部署:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: registry
labels:
app: registry
role: registry
spec:
replicas: 1
selector:
matchLabels:
app: registry
template:
metadata:
labels:
app: registry
spec:
containers:
- name: registry
image: registry:latest
ports:
- containerPort: 5000
volumeMounts:
- mountPath: '/registry'
name: registry-volume
volumes:
- name: registry-volume
hostPath:
path: '/data'
type: Directory

服务:
apiVersion: v1
kind: Service
metadata:
name: registry
namespace: default
labels:
app: registry
spec:
selector:
role: registry
type: NodePort
ports:
- name: registry
nodePort: 31001
port: 5000
protocol: TCP

创建部署/服务时,一切都很好。 kubectl将状态显示为 Running,用于服务和部署:
NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/registry 1 1 1 1 30m

NAME DESIRED CURRENT READY AGE
rs/registry-6549cbc974 1 1 1 30m

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/registry 1 1 1 1 30m

NAME DESIRED CURRENT READY AGE
rs/registry-6549cbc974 1 1 1 30m

NAME READY STATUS RESTARTS AGE
po/registry-6549cbc974-mmqpj 1/1 Running 0 30m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 37m
svc/registry NodePort 10.0.0.6 <none> 5000:31001/TCP 7m

但是,当我尝试使用 minikube service registry --url获取用于服务的外部IP时,它超时/失败: Waiting, endpoint for service is not ready yet...

当我删除服务(保持部署完好无损)并使用 kubectl expose deployment registry --type=NodePort手动公开部署时,我能够使其正常运行。

可以在 here中找到Minikube日志。

最佳答案

您需要在spec.selector服务 list 中指定正确的registry:

apiVersion: v1
kind: Service
metadata:
name: registry
namespace: default
labels:
app: registry
spec:
selector:
app: registry
type: NodePort
ports:
- name: registry
nodePort: 31001
port: 5000
protocol: TCP

现在, registry服务正确指向 registry Pane :
$ kubectl get endpoints
NAME ENDPOINTS AGE
kubernetes 10.0.2.15:8443 14m
registry 172.17.0.4:5000 4s

您也可以获取外部网址:
$ minikube service registry --url
http://192.168.99.106:31001

关于kubernetes - Minikube无法使用Yaml公开服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47299087/

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