1、在master节点创建一个yaml文件,比如service.yaml
文件内容如下apiVersion: v1 kind: Service metadata: name: "servicename" namespace: "ns000000000000000000001" labels: svc: "apiService" spec: type: "NodePort" ports: - port: 18888 targetPort: 18888 nodePort: 38888 protocol: TCP name: apiService-http selector: hwsapp: "apiService" sessionAffinity: ClientIP
然后执行kubectl create -f service.yaml命令
就可以将容器内1888端口的服务映射到node节点上的3888端口给外部访问