如果想從外部訪問剛剛布置好的nginx服務(wù),還需要配置service
nginx-service.yaml
kind: Service
apiVersion: v1
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30001
$ kubectrl apply -f nginx-service.yaml
sepc.type:指定service 的類型為NodePort
spec.selector: 指定要暴露的pod的標(biāo)簽
spec.ports.port: 供集群中其它c(diǎn)ontainer訪問端口
spec.ports.targetPort: 指向container暴露出來的端口
spec.ports.nodePort: 外部訪問的端口
需要注意的是spec.ports.nodePort的默認(rèn)范圍是30000-32767,設(shè)置這個(gè)范圍之外的值會(huì)報(bào)錯(cuò)