美文网首页
Service 服务发现(Cluster IP & NodePo

Service 服务发现(Cluster IP & NodePo

作者: 懒猫睡醒了 | 来源:发表于2022-05-19 08:25 被阅读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

    相关文章

      网友评论

          本文标题:Service 服务发现(Cluster IP & NodePo

          本文链接:https://www.haomeiwen.com/subject/sclaurtx.html