如何使用 Kubernetes 中的 NodePort 服务在公共 IP 上公开 nginx?

Jee*_*eel 3 containers kubernetes kubectl

我正在执行kubectl create -f nginx.yaml,成功创建了 Pod。但 PODS 未在我的实例的公共 IP 上公开。以下是我使用的 YAML,服务类型为节点端口:

 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
Run Code Online (Sandbox Code Playgroud)

我的方法或上述 YAML 文件中可能存在哪些不正确的地方,无法将部署时的 pod 公开到公共 IP?

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

Jee*_*eel 6

未添加端点。在调试时,我发现部署和服务之间的标签不匹配。因此,将标签类型从“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
Run Code Online (Sandbox Code Playgroud)