zoukankan      html  css  js  c++  java
  • service代理模式及负载均衡

    [root@k8s-master ~]# vim service.yaml

    apiVersion: v1

    kind: Service

    metadata:

      name: my-service

    spec:

      selector:

        app: MyApp

      ports:

      - name: http

        protocol: TCP

        port: 80

        targetPort: 80

      - name: https

        protocol: TCP

        port: 443

    targetPort: 443

    [root@k8s-master ~]# kubectl get all

    NAME                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE

    svc/kubernetes      ClusterIP   10.10.10.1    <none>        443/TCP   5d

    svc/nginx-service   ClusterIP   10.10.10.85   <none>        88/TCP    20h

    [root@k8s-master ~]# kubectl create -f service.yaml

    [root@k8s-master ~]# kubectl get svc

    NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE

    kubernetes      ClusterIP   10.10.10.1     <none>        443/TCP          5d

    my-service      ClusterIP   10.10.10.212   <none>        80/TCP,443/TCP   24s

    nginx-service   ClusterIP   10.10.10.85    <none>        88/TCP           20h

    查看pod的标签,用标签来识别,并代理到后端的服务上

    [root@k8s-master ~]# kubectl get pod --show-labels -o wide

    nginx-pod                           1/1       Running   1          17h       172.17.80.4   192.168.30.23   app=nginx

    修改我们创建的my-service,把标签改为nginx,然后我们访问我们的my-service分配的clusterIP就能直接代理到后端的Nginx上了

    [root@k8s-master ~]# kubectl edit svc/my-service

    访问10.10.10.212:80

    [root@k8s-node1 ~]# curl 10.10.10.212:80

    <!DOCTYPE html>

    <html>

    <head>

    <title>Welcome to nginx!</title>

    [root@k8s-node2 ~]# curl 10.10.10.212:80

    <!DOCTYPE html>

    <html>

    <head>

    <title>Welcome to nginx!</title>

  • 相关阅读:
    Weebly轻松创建个人网站
    人生如游戏
    1 欧拉角与四元数计算机动画笔记
    图形学相关的一些数学基础书
    1047 Student List for Course (25 分)
    1124 Raffle for Weibo Followers (20 分)
    1065 A+B and C (64bit) (20 分)
    1036 Boys vs Girls (25 分)
    1039 Course List for Student (25 分)
    1054 The Dominant Color (20 分)
  • 原文地址:https://www.cnblogs.com/zc1741845455/p/11158298.html
Copyright © 2011-2022 走看看