Service 服务发现(Cluster IP & NodePo

2022-05-19  本文已影响0人  懒猫睡醒了

Cluster IP

1.创建Service

root@k8s-master:~# kubectl expose deployment maydep --port=8080 --target-port=80
service/maydep exposed

2.查看Service

root@k8s-master:~# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 41h
maydep ClusterIP 10.102.112.40 <none> 8080/TCP 49s

3.测试服务的可用性

root@k8s-master:~# curl 10.102.112.40:8080
<html><body><h1>It works!</h1></body></html>
root@k8s-master:~#

4.删除服务

root@k8s-master:~# kubectl delete service maydep
service "maydep" deleted
root@k8s-master:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42h

NodePort

1.创建NodePort Service

root@k8s-master:~# kubectl expose deployment maydep --port=8080 --target-port=80 --type=NodePort
service/maydep exposed

2.查看Service

root@k8s-master:~# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42h
maydep NodePort 10.110.234.148 <none> 8080:32591/TCP 2m49s

3.浏览器访问对应信息,IP为node/master的IP + 端口为32591

image.png
上一篇下一篇

猜你喜欢

热点阅读