注意selector一定要书写正确,否则通过集群IP:端口 或者是节点ip:外部访问端口 都无法访问
apiVersion: v1
kind: Pod
metadata:
name: test-pod
namespace: test
labels:
environment: stg
spec:
containers:
- name: my-nginx-container
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- name: nginx-port
containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: svc-nginx
namespace: test
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
environment: stg
type: NodePort