我正在执行kubectl create -f nginx.yaml,它成功地创建了pods。但是实例的公网IP上没有暴露实例实例的PODS。以下是我使用的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部署到公网IP时,可能会有什么不正确的地方?
PS:防火墙和ACL在所有TCP上都对互联网开放
发布于 2018-02-19 17:00:58
Jeel是对的。您的服务选择器与Pod标签不匹配。
如果你像Jeel已经在这个答案中添加的那样进行修复
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
name: http
selector:
name: nginx您的服务将显示在Node IP地址中。因为您的服务类型为NodePort。
如果您的节点IP是35.226.16.207,您可以使用此IP和NodePort连接到您的Pod
$ curl 35.226.16.207:30080在这种情况下,您的节点必须具有公网IP。否则,您将无法访问
第二个选项,您可以创建LoadBalancer类型服务
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: LoadBalancer
ports:
- port: 80
name: http
selector:
name: nginx这将为您提供一个公网IP。
有关更多详细信息,请访问check this
发布于 2018-02-19 14:18:41
未添加终结点。在调试过程中,我发现deployment和Service之间的标签不匹配。因此,将标签类型从"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: nginxhttps://stackoverflow.com/questions/48857092
复制相似问题