kubernetes publishing service
Create a pod in the Kubernetes cluster and verify that it is running normally:
# 拉取nginx 的pod
[root@zjj101 ~]# kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
# 查看pod ,发现了一个nginx,等status状态变成running状态后就可以了
[root@zjj101 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-f89759699-rh5lk 1/1 Running 0 2m19s
The external port is exposed. If you do not expose it, the external network cannot be accessed. The default port of nginx is 80
命令: kubectl expose deployment nginx --port=80 --type=NodePort
[root@zjj101 ~]# kubectl expose deployment nginx --port=80 --type=NodePort
service/nginx exposed
View external ports: kubectl get pod,svc
[root@zjj101 ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-f89759699-rh5lk 1/1 Running 0 5m10s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15m
service/nginx NodePort 10.98.67.59 <none> 80:31715/TCP 46s
It is found that the port exposed by nginx is 31715
Open the browser and test it
zjj101 zjj102 zjj103 I did host mapping on the windows machine.In fact, zjj101 is the master machine, zjj102 is the node1 machine, and zjj103 is the node2 machine.
http://zjj101:31715/
http://zjj102:31715/
http://zjj103:31715/