kubectl-NodePort
NodePort的本质为ipvs和iptables,所以它工作在第四层,专注与端口服务的发布
-
创建资源文件
--- kind: Service apiVersion: v1 metadata: name: nodeport-nginx spec: type: NodePort ports: - protocol: TCP port: 80 targetPort: 80 nodePort: 30080 #指定暴露端口(30000-32767) selector: app: nginx -
创建service
kubectl apply -f nodeport.yml -
查看service资源
[root@k8s-master k8s-ymls]# kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE clusterip-nginx ClusterIP 10.254.196.219 <none> 80/TCP 47s headless-nginx ClusterIP None <none> 80/TCP 22h kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 7d23h nodeport-nginx NodePort 10.254.23.245 <none> 80:30080/TCP 3s -
访问任意集群内的
节点ip+上方暴露的端口号即可外部访问服务curl http://10.10.10.101:30080