gpt4 book ai didi

kubernetes - 如何在 Kubernetes 中使用 NodePort 服务在公共(public) Ip 上公开 nginx?

转载 作者:行者123 更新时间:2023-12-02 11:54:34 24 4
gpt4 key购买 nike

我正在执行 kubectl create -f nginx.yaml 成功创建了 pod。但是 PODS 没有暴露在我实例的公共(public) IP 上。以下是我使用的 YAML,服务类型为 nodeport:

 apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
name: http
- port: 443
nodePort: 30443
name: https
selector:
name: nginx

我的方法或上面的 YAML 文件在将部署时的 pod 暴露给公共(public) IP 时有什么不正确的地方?

PS:防火墙和 ACL 在所有 TCP 上对互联网开放

最佳答案

没有添加端点。在调试时我发现部署和服务之间的标签不匹配。因此,将标签类型从“app”更改为“name”,它起作用了。

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
name: nginx
spec:
replicas: 3
selector:
matchLabels:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
name: http
selector:
name: nginx

关于kubernetes - 如何在 Kubernetes 中使用 NodePort 服务在公共(public) Ip 上公开 nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48857092/

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