通过service暴露端口:
[root@master ~]# cat 6-5nodeport.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
ports:
- port: 8008
name: nginx-service80
protocol: TCP
targetPort: 80
nodePort: 31999
selector:
app: nginx
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: registry.cn-beijing.aliyuncs.com/qingfeng666/nginx:latest
name: nginx
[root@master ~]# kubectl get service --all-namespaces
NAMESPACE