娉�锛�����浣跨�ㄧ��Traefik涓�1.x������

�ㄧ��河渠х��澧�涓�锛���浠�甯稿父��瑕��у�舵�ヨ��河渠���缃���澶��ㄨ��ラ��缇や腑锛���杩��板阀��Ingress����璐c��

 
Ingress��涓昏�������广大�HTTP��HTTPS浠���缇ゅ��ㄦ�拈�茬�璇ラ��缇や腑杩�琛������°��杩�涓�Ingress�у�跺�浣�广大�澶��ㄦ���璺��卞�伴��缇ゆ��寮��插��宸ヤ�濡����ヤ��ワ���浠�涓句�涓�疏浚�����岛�海洋��ユ�存�妤���璇存��Ingress��姒�蹇点��

 

兄弟���锛��宠薄涓�涓��ㄤ���Kubernetes��缇や腑���ュ共涓�寰����★�广大���搴��ㄧ�搴�涔��村郊姝ら��淇★���杩�河渠����¤�藉��ㄩ��缇ゅ���ㄨ�璁块��锛�浣���浠��宠�╂��浠����ㄦ�蜂���缇ゅ��ㄤ��藉�璁块��疏浚�浠�����姝わ���浠���瑕�������浣跨�ㄥ����浠g��广大�姣�涓�HTTP锛�S锛�锛�岛�濡�锛�service.yourdomain.com锛�璺��变��稿�����绔��宠��锛�骞跺�ㄨ�ユ���$��涓���疏浚�岛�涔��达�濡�锛�pod锛�杩�琛�璐�潘藉��琛°��涓�姝ゅ���讹��变�Kubernetes���ц水浼�涓�����������锛���姝ゆ��浠�甯���璺�韪����″��绔����存�戊寅�浠ヤ究�藉��ㄦ房�������ゆ��Pod�跺�杩�河渠�HTTP璺��遍���板�宠���版��Pod疏浚�岛���
 

浣跨��Ingress璧�婧����宠����Ingress Controller锛�浣���浠ュ���颁互涓�����锛�

 

  • 广大�浣�����app.domain.com����浣���绉���缃�缁�涓���寰����″��ㄧ�搴�

  • 广大�璺�寰�domain.com/web����浣���绉���缃�缁�涓���寰�����web

  • 广大�浣�����backend.domain.com����浣���绉���缃�缁�涓���寰����″��绔�锛�骞跺�ㄨ�ュ井���$��澶�涓�疏浚�岛�涔��达�Pod锛�杩�琛�璐�潘藉��琛�
  •  

    �板��锛�浣���瑙d�Ingress����瑕��с��疏浚��藉�甯��╁�HTTP璺��辨������Kubernetes��缇や腑�瑰����寰����°��

     
    浣���锛�娴���璺��卞苟涓���Ingress��Kubernetes涓�����涓����姐��岛�濡�锛�杩���浠ュ�Ingress��缃�涓鸿�潘藉��琛℃����颁���搴��ㄧ�搴���缁�姝�SSL���ц��轰���绉扮������涓绘�恒���ㄤ������′��村����娴�����璁剧疆���¤�块��瑙���绛���

     

    Kubernetes��涓�涓��瑰����Ingress API璧�婧�锛�疏浚��藉�����涓�杩版�������姐��浣���锛�绠����板��寤轰�涓�Ingress API璧�婧���娌℃��浣��ㄧ����浣�杩���瑕�涓�涓�Ingress Controller������锛�Kubernetes����璁稿�Ingress controller锛�濡�Contour��HAProxy��NGINX浠ュ��Traefik��

     

    �ㄦ����涓�锛���广大�浣跨��Traefik Ingress Controller��寤�Ingress��疏浚��藉�疏浚��扮演�颁唬HTTP����浠g����璐�潘藉��琛″�ㄧ�����斤�浠���绠���河渠�寰����$���ㄧ讲��姝ゅ�锛�Traefik瀵�Docker��Marathon��Consul��Kubernetes��Amazon ECS绛�绯荤�����澧��芥��岛�河渠�寮哄ぇ��������
     
    疏浚�����绋�涓ㄥ�浣���K8S��缇や腑�ㄧ讲Traefik Ingress Controller
     
    Traefik瀵逛�璇稿�Kubernetes涔�绫荤���垫椿�ц�寮虹��绯荤��������ㄣ����Kubernetes涓�锛�姣�澶╅��瑕�澶�娆℃房�������ゆ����绾ф���★���Traefik��浠ョ�������¢����浠�搴�/缂����� API骞剁���崇�������存�拌矾�憋���姝や���寰����℃�������ㄩ��缃��冲��涓�澶���杩��ャ��
     

    �ゆ�や�澶�锛�Traefik����澶�涓�璐�潘藉��琛$��娉���Let��s Encrypt��HTTPS锛���������璇�涔�锛�����璺��ㄣ��WebSoket��GRPC��澶�涓����х�搴�锛�Rest��Prometheus��Statsd��Datadog��InfluxDB绛�锛�������Traefik涓����ㄥ���界���村�淇℃��锛�璇峰�����跺���规��妗o�
     
    https://docs.traefik.cn/
     

    Ingress 璧�婧�

     
    �ㄦ��绋�寮�彭�涔���锛���浠����ョ�����拌�ㄨ�轰�涓�Ingress璧�婧���濡�浣�宸ヤ�����浠ヤ�����寮�浣跨��Nginx Ingress Controller��Ingress绀轰���
     

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: ingress-example
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /microservice1
            backend:
              serviceName: test
              servicePort: 80

     
    浠ヤ�Ingress manifest ����河渠�涓�绯诲��HTTP瑙���锛�疏浚�浠��ㄤ�瑙�疏浚�controller濡�浣�璺��辨�����

     

    ����涓绘�恒��濡�������疏浚�涓绘�虎�濡�涓���绀猴�锛���璇ヨ������ㄤ���杩���疏浚�IP�板���������ョ��HTTP娴�����濡�����岛�河渠�涓绘�虎�濡�yourhost.com锛�锛���璇ヨ���浠����ㄤ�璇ヤ富�恒��

     
    涓�涓�璺�寰���琛�锛�濡�锛�/microservice1锛�锛�疏浚�������serviceName��servicePort疏浚�涔����宠����绔���

     

    涓�涓���绔�����Ingress���雾��HTTP锛���HTTPS锛�璇锋�广大�涓�缁�疏浚�瑙�����涓绘�哄��璺�寰��归��锛��跺��广大��惰矾�卞�拌�ヨ���涓���疏浚�����绔����°��

     

    �ㄤ互涓�岛�海洋�涓�锛���浠���缃�河渠�涓�涓���涓衡��test������绔�锛�疏浚�广大��ユ�舵�����ヨ��/microservice璺�寰���娴������惰��锛���浠�涔���浠ラ��缃�涓�涓�榛�璁ゅ��绔�锛�疏浚�广大�广大�涓轰换浣�涓�绗���瑙���涓�璺�寰����ㄦ�疯�锋���岛����°�����讹�濡���涓�疏浚�涔�浠讳�瑙���锛�Ingress广大�璺��辨����娴����伴�璁ゅ��绔���岛�濡�锛�
     

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: test-ingress
    spec:
      backend:
        serviceName: defaultbackend
        servicePort: 80

     
    �ㄦ��岛�涓�锛�����娴����借�潘����伴�璁ゅ��绔�涓�defaultbackend���板��锛���浠���瑙d�Ingress 璧�婧����烘��姒�蹇碉��ヤ��ユ��浠��ョ����涓�河渠��蜂���岛�海洋���
     

    Step 0锛�������澶�

     

    濡�涓�����浠���璇寸��锛�疏浚�涔�涓�涓�Ingress璧�婧�娌℃��浠讳�浣���锛��ら��浣�浣跨�ㄤ�Ingress Controller���ㄦ����绋�涓�锛���浠���Kubernetes��缇や腑灏�Traefik璁剧疆涓�Ingress Controller��

     

    瑕�疏浚�����绋�锛�浣���瑕�杩�琛�浠ヤ���澶�锛�

     

  • 涓�涓�姝e�ㄨ�琛���Kubernetes��缇ゃ��

  • 涓�涓�疏浚�瑁�濂界���戒护琛�宸ュ�凤�kubectl��骞堕��缃�涓轰���缇ら��淇°��
  •  

    璇锋敞��锛�浠ヤ�绀轰�����璁句��ㄦ���拌�$��涓�浣跨��Minikube杩�琛�Kubernetes��缇ゃ��
     

    Step 1锛�����RBAC

     

    兄弟���锛���浠���瑕���Traefik��河渠�涓�河渠�����锛�浠ヨ�块����缇や腑杩�琛���Pod��endpoint�����°��涓烘�わ���浠�广大�浣跨��ClusterRole��ClusterRoleBinding璧�婧���浣���锛�浣�涔���浠ュ�瑰�藉��绌洪�磋���村����RoleBindings浣跨�ㄦ��广大��规���规�����甯革�濡�����缇ょ���藉��绌洪�翠�浼��ㄦ���存�戊寅�骞朵�Traefik��娉���瑙�������缇ょ���藉��绌洪�达��d�杩���兄弟������规���
     

    璁╂��浠���寤轰�涓��扮演��ServiceAccount锛�涓�Traefik��岛���缇や腑��韬�浠姐��
     

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: traefik-ingress
      namespace: kube-system

     
    瑕���寤轰�涓�ServiceAccount锛���瑕���traefik-service-acc.yaml涓�淇�海洋�浠ヤ�manifest骞惰�琛�锛�
     

    kubectl create -f traefik-service-acc.yaml
    serviceaccount "traefik-ingress" created

     
    �ヤ��ワ�璁╂��浠���寤轰�涓��锋��涓�缁�������ClusterRole锛�璇ユ����广大�搴��ㄤ�Traefik ServiceAccount����杩�ClusterRole锛�Traefik��浠ョ�$������瑙���缇や腑�����藉��绌洪�翠腑��璧�婧�锛�岛�濡����°��endpoint��secret浠ュ��Ingress��
     

    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: traefik-ingress
    rules:
      - apiGroups:
          - ""
        resources:
          - services
          - endpoints
          - secrets
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - extensions
        resources:
          - ingresses
        verbs:
          - get
          - list
          - watch

     
    广大�杩�涓�瑙���淇�海洋��版��浠�traefik-cr.yaml涓�锛�骞惰�琛�锛�
     

    kubectl create -f traefik-cr.yaml
    clusterrole.rbac.authorization.k8s.io ��traefik-ingress�� created

     
    ����锛����ㄨ�河渠�����锛���浠�搴�璇ュ�ClusterRole缁�疏浚���Traefik ServiceAccount涓���浣跨��ClusterRoleBinding manifest��浠ュ����杩�涓���浣�锛�
     

    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: traefik-ingress
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: traefik-ingress
    subjects:
    - kind: ServiceAccount
      name: traefik-ingress
      namespace: kube-system

     
    淇�海洋�杩�涓�瑙�����traefik-crb.yaml涓�锛�骞惰�琛�浠ヤ��戒护锛�
     

    kubectl create -f traefik-crb.yaml
    clusterrolebinding.rbac.authorization.k8s.io ��traefik-ingress�� created

     

    Step 2锛��ㄧ讲Traefik�伴��缇�

     

    �ヤ��ワ���浠�广大��ㄧ讲Traefik��Kubernetes��缇ゃ��疏浚���Traefik��妗f����涓�绉�绫诲�����ㄧ讲锛�浣跨��Deployment瀵硅薄��浣跨��DaemonSet瀵硅薄��浣跨��Helm Chart��
     

    �ㄦ����绋�涓�锛���浠�广大�浣跨��Deployment manifest���告���朵���椤癸�Deployment��璇稿�浼��裤��岛�濡�锛�疏浚�浠��界‘淇��村ソ����浼哥缉�э�骞朵负婊��ㄦ�存�版��岛���濂芥������

     
    璁╂��浠���涓�涓� Deployment manifest锛�
     

    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: traefik-ingress
      namespace: kube-system
      labels:
        k8s-app: traefik-ingress-lb
    spec:
      replicas: 1
      selector:
        matchLabels:
          k8s-app: traefik-ingress-lb
      template:
        metadata:
          labels:
            k8s-app: traefik-ingress-lb
            name: traefik-ingress-lb
        spec:
          serviceAccountName: traefik-ingress
          terminationGracePeriodSeconds: 60
          containers:
          - image: traefik
            name: traefik-ingress-lb
            ports:
            - name: http
              containerPort: 80
            - name: admin
              containerPort: 8080
            args:
            - --api
            - --kubernetes
            - --logLevel=INFO

     
    杩�涓�Deployment广大���kube-system �藉��绌洪�翠腑��寤轰�涓�Traefik������Traefik疏浚瑰�ㄥ�浣跨�ㄦ��manifest涓���疏浚���绔���80��8080��

     
    广大�杩�涓�manifest淇�海洋���traefik-deployment.yaml��浠朵腑锛�骞惰�琛�浠ヤ��戒护��寤�Deployment锛�
     

    kubectl create -f traefik-deployment.yaml
    deployment.extensions ��traefik-ingress�� created

     
    �板��锛�璁╂��浠�妫��ヤ�涓�Traefik Pod�����芥������寤轰�锛�
     

    kubectl --namespace=kube-system get pods
    NAME                         READY     STATUS    RESTARTS   AGE
    ....
    storage-provisioner           1/1       Running   3          23d
    traefik-ingress-54d6d8d9cc-ls6cs 1/1       Running   0          1m

     
    濡�浣���瑙�锛�Deployment Controller���ㄤ�涓�涓�Traefik����锛�骞跺�ㄦ�e�ㄨ�琛�锛��叉���锛�
     

    Step 3锛�涓哄��ㄨ�块����寤�NodePorts

     
    璁╂��浠���寤轰�涓����℃�ヤ���缇ゅ��ㄨ�块��Traefik��涓烘�わ���浠���瑕�涓�涓��拈�蹭袱涓�NodePorts�����°��
     

    kind: Service
    apiVersion: v1
    metadata:
      name: traefik-ingress-service
      namespace: kube-system
    spec:
      selector:
        k8s-app: traefik-ingress-lb
      ports:
        - protocol: TCP
          port: 80
          name: web
        - protocol: TCP
          port: 8080
          name: admin
      type: NodePort

     
    广大�杩�涓�manifest淇�海洋���traefik-svc.yaml锛�骞跺��寤烘���★�
     

    kubectl create -f traefik-svc.yaml
    service ��traefik-ingress-service�� created

     
    �板��锛�璁╂��浠�楠�璇�璇ユ���℃������寤猴�
     

    
    kubectl describe svc traefik-ingress-service --namespace=kube-system
    Name:                     traefik-ingress-service
    Namespace:                kube-system
    Labels:                   <none>
    Annotations:              <none>
    Selector:                 k8s-app=traefik-ingress-lb
    Type:                     NodePort
    IP:                       10.102.215.64
    Port:                     web  80/TCP
    TargetPort:               80/TCP
    NodePort:                 web  30565/TCP
    Endpoints:                172.17.0.6:80
    Port:                     admin  8080/TCP
    TargetPort:               8080/TCP
    NodePort:                 admin  30729/TCP
    Endpoints:                172.17.0.6:8080
    Session Affinity:         None
    External Traffic Policy:  Cluster
    Events:                   <none>

     
    濡�浣���瑙�锛���浠��板�ㄦ��涓や锅NodePorts锛�web��admin锛�锛�疏浚�浠�����璺��卞��Traefik Ingress Controller��80��8080疏浚瑰�ㄧ���c����admin�� NodePort广大��ㄤ�璁块��Traefik Web UI锛���web�� NodePort广大��ㄤ�璁块����杩�Ingress�拈�茬�����°��
     

    Step 4锛�璁块��Traefik

     

    涓轰��藉�ㄦ�瑙��ㄤ腑璁块��Traefik Web UI锛�浣���浠ヤ娇�ㄢ��admin��NodePort 30729锛�璇锋敞��锛�浣���NodePort�煎���戒�����涓���锛�����涓烘��浠�杩�娌℃��娣诲��浠讳���绔�锛���浠�UI姝ゆ�跺�璇ユ��绌虹����

     

    �变���浠�广大���缁�Traefik杩�琛�浠讳���缃�锛���姝ゆ��浠�浼��跺��404����搴���
     

    curl $(minikube ip):30565
    404 page not found

     

    Step 5 锛�娣诲��Ingress �伴��缇�

     

    �板�ㄦ��浠���Kubernetes��缇や腑宸茬�广大�Traefik浣�涓�Ingress Controller河渠����惰��锛���浠�岛��ч��瑕�疏浚�涔�Ingress璧�婧����拈��Traefik Web UI�����°��

     

    兄弟���锛���浠���寤轰�涓����★�
     

    apiVersion: v1
    kind: Service
    metadata:
      name: traefik-web-ui
      namespace: kube-system
    spec:
      selector:
        k8s-app: traefik-ingress-lb
      ports:
      - name: web
        port: 80
        targetPort: 8080

     
    淇�海洋�manifest��traefik-webui-svc.yaml涓�锛�骞惰�琛�锛�
     

    kubectl create -f traefik-webui-svc.yaml
    service ��traefik-web-ui�� created

     
    璁╂��浠�楠�璇����℃����宸茬���寤猴�
     

    kubectl describe svc traefik-web-ui --namespace=kube-system
    Name:              traefik-web-ui
    Namespace:         kube-system
    Labels:            <none>
    Annotations:       <none>
    Selector:          k8s-app=traefik-ingress-lb
    Type:              ClusterIP
    IP:                10.98.230.58
    Port:              web  80/TCP
    TargetPort:        8080/TCP
    Endpoints:         172.17.0.6:8080
    Session Affinity:  None
    Events:            <none>

     
    濡�浣���瑙�锛����$��ClusterIP��10.98.230.58锛�骞跺��manifest涓�������疏浚�绔��c��
     
    �ヤ��ワ���浠���瑕���寤轰�涓�Ingress璧�婧�锛�����Traefik Web UI��绔�锛�
     

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: traefik-web-ui
      namespace: kube-system
    spec:
      rules:
      - host: traefik-ui.minikube
        http:
          paths:
          - path: /
            backend:
              serviceName: traefik-web-ui
              servicePort: web

     
    ��璐ㄤ�锛�Ingress广大�����璇锋�璺��卞��traefik-ui.minikube锛��ㄤ�杩版�ラ�や腑��寤虹�����℃�拈��Traefik Web UI��
     

    广大�瑙���淇�海洋���traefik-ingress.yaml锛�骞惰�琛�锛�
     

    kubectl create -f traefik-ingress.yaml
    ingress.extensions ��traefik-web-ui�� created

     
    涓轰��藉���杩�traefik-ui.minikube�ㄦ�瑙��ㄤ腑��浠ヨ�块��Traefik Web UI锛���浠���瑕�娣诲���扮演���$���版��浠�/etc/hosts��浠朵腑��璇ユ�$��广大�����Minikube IP��涓绘�哄����浣���浠ラ��杩�杩�琛�minikube ip�ヨ�山��minkube疏浚�岛���IP�板��锛��跺��广大��颁富�雾����绉颁�海洋���/etc/hosts��浠朵腑锛�濡�涓���绀猴�
     

    echo "$(minikube ip) traefik-ui.minikube" | sudo tee -a /etc/hosts
    192.168.99.100 traefik-ui.minikube

     
    �板��锛�浣�搴�璇ヨ�藉��ㄦ�瑙��ㄤ腑璁块��http://traefik-ui.minikube:&lt;AdminNodePort&gt;骞舵�ョ��Traefik Web UI����蹇�河渠�������admin��NodePort�颁富�哄�板����
     
    疏浚�����绋�涓ㄥ�浣���K8S��缇や腑�ㄧ讲Traefik Ingress Controller
     
    ��dashboard涓�锛�浣���浠ョ�瑰��Health �炬�ユ�ユ�ョ��搴��ㄧ�搴����ュ悍�跺�碉�
     
    疏浚�����绋�涓ㄥ�浣���K8S��缇や腑�ㄧ讲Traefik Ingress Controller
     

    Step 6锛�疏浚��板�轰���绉扮��璺���

     

    �板��锛���浠��ユ�绀哄�浣�浣跨��Traefik Ingress Controller涓哄��绔���琛ㄨ�剧疆�轰���绉扮��璺��便����浠�广大�浣跨�ㄧ��������椤电�绔���寤�3涓�Deployment锛�骞舵�剧ず�ㄧ�╁�惧��锛�����������椹奸箍��
     

    ---
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: bear
      labels:
        app: animals
        animal: bear
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: animals
          task: bear
      template:
        metadata:
          labels:
            app: animals
            task: bear
            version: v0.0.1
        spec:
          containers:
          - name: bear
            image: supergiantkir/animals:bear
            ports:
            - containerPort: 80
    ---
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: moose
      labels:
        app: animals
        animal: moose
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: animals
          task: moose
      template:
        metadata:
          labels:
            app: animals
            task: moose
            version: v0.0.1
        spec:
          containers:
          - name: moose
            image: supergiantkir/animals:moose
            ports:
            - containerPort: 80
    ---
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: hare
      labels:
        app: animals
        animal: hare
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: animals
          task: hare
      template:
        metadata:
          labels:
            app: animals
            task: hare
            version: v0.0.1
        spec:
          containers:
          - name: hare
            image: supergiantkir/animals:hare
            ports:
            - containerPort: 80

     
    姣�涓�Deployment�藉���涓や锅Pod����锛���姣�涓�Pod广大���containerPort 80涓����♀���ㄧ�┾��缃�绔���
     

    璁╂��浠�淇�海洋�杩�河渠�Deployment manifest��animals-deployment.yaml涓�锛�骞惰�琛�锛�
     

    kubectl create -f animals-deployment.yaml
    deployment.extensions ��bear�� created
    deployment.extensions ��moose�� created
    deployment.extensions ��hare�� created

     
    �板��锛�璁╂��浠�涓烘��涓�Deployment��寤轰�涓����★�浣垮�Pod��浠ヨ�块��锛�
     

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: bear
    spec:
      ports:
      - name: http
        targetPort: 80
        port: 80
      selector:
        app: animals
        task: bear
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: moose
    spec:
      ports:
      - name: http
        targetPort: 80
        port: 80
      selector:
        app: animals
        task: moose
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: hare
      annotations:
        traefik.backend.circuitbreaker: "NetworkErrorRatio() > 0.5"
    spec:
      ports:
      - name: http
        targetPort: 80
        port: 80
      selector:
        app: animals
        task: hare

     
    璇锋敞��锛�绗�涓�椤规���′娇�ㄦ��璺���annotation����璺��ㄦ��Traefik��涓�椤瑰���斤����叉�㈠�������������″�ㄦ�垮��楂�璐�潘姐���ㄦ��岛�涓�锛���浠��叉�㈡���″�ㄤ���楂�璐�潘借�杩�50%��褰�姝ゆ�′欢�归���讹�CB杩��モ��璺抽�糕���舵��锛��ㄨ�ョ�舵��涓�疏浚�浼�浣跨�ㄩ�疏浚�涔���HTTP�舵��浠g��杩�琛���搴�����疏浚����板��涓�涓���绔���

     

    淇�海洋�杩�河渠�����manifest��animals-svc.yaml骞惰�琛�锛�
     

    kubectl create -f animals-svc.yaml
    service ��bear�� created
    service ��moose�� created
    service ��hare�� created

     
    ����锛�涓烘��涓�Deployment��寤轰�涓���3涓�����绔�瀵圭��Ingress��bear.minikube��moose.minikube��hare.minikube广大�����浠������稿���绔����$����绔���
     

    Ingress manifest濡�涓���绀猴�
     

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: animals
      annotations:
        kubernetes.io/ingress.class: traefik
    spec:
      rules:
      - host: hare.minikube
        http:
          paths:
          - path: /
            backend:
              serviceName: hare
              servicePort: http
      - host: bear.minikube
        http:
          paths:
          - path: /
            backend:
              serviceName: bear
              servicePort: http
      - host: moose.minikube
        http:
          paths:
          - path: /
            backend:
              serviceName: moose
              servicePort: http

     
    淇�海洋�瑙�����animals-ingress.yaml骞惰�琛�锛�
     

    kubectl create -f animals-ingress.yaml
    ingress.extensions ��animals�� created

     
    �板��锛���Traefik dashboard��锛�浣���浠ョ���版��涓�涓绘�雾����绔�浠ュ���稿�����绔���琛�锛�
     
    疏浚�����绋�涓ㄥ�浣���K8S��缇や腑�ㄧ讲Traefik Ingress Controller
     
    濡���浣���娆$�杈�etc/hosts锛�浣�搴�璇ヨ�藉��ㄤ���娴�瑙��ㄤ腑璁块���ㄧ�╃�椤碉�
     

    echo ��$(minikube ip) bear.minikube hare.minikube moose.minikube�� | sudo tee -a /etc/hosts

     
    浣�搴�璇ヤ娇�ㄢ��web��NodePort�ヨ�块���瑰��缃�椤线��岛�濡�锛�http://bear.minikube:&lt;WebNodePort&gt;

     

    ��浠�涔���浠ュ�涓�涓���绔����伴��缃�涓哄�ㄤ�涓���涓���岛����★�濡�涓���绀猴�
     

    
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: all-animals
      annotations:
        kubernetes.io/ingress.class: traefik
        traefik.frontend.rule.type: PathPrefixStrip
    spec:
      rules:
      - host: animals.minikube
        http:
          paths:
          - path: /bear
            backend:
              serviceName: bear
              servicePort: http
          - path: /moose
            backend:
              serviceName: moose
              servicePort: http
          - path: /hare
            backend:
              serviceName: hare
              servicePort: http

     
    濡���浣�婵�娲昏�涓�Ingress锛�浣跨�ㄧ�稿���璺�寰�锛�涓�涓��ㄧ�╁�ㄤ�涓���涓��借�藉�璁块������animals.minikube����蹇�河渠�广大�杩�涓���娣诲����/etc/hosts��
     

    echo ��$(minikube ip) animals.minikube�� | sudo tee -a /etc/hosts

     
    璇锋敞��锛���浠�姝e�ㄩ��缃�Traefik锛�浠ヤ娇��traefik.frontend.rule.type娉ㄩ��锛�浠�URL璺�寰�涓����ゅ��缂���杩��锋��浠���浠ョ�存�ヤ娇�ㄤ�涓�涓�绀轰�涓���疏浚瑰�ㄣ���变�traefik.frontend.rule.type: PathPrefixStrip瑙���锛�浣�蹇�椤讳娇��http://animals.minikube:32484/moose/��涓���http://animals.minikube:32484/moose
     

    Step 7锛�疏浚��版�������

     

    ����Traefik锛��ㄦ�山��浠ヤ娇�ㄦ���℃����浠ュ���ф�瑰��ㄥ�涓�deployment涔��村����Ingress娴�����杩�涓����藉���ㄤ���涓�����甯�锛�疏浚�����搴�璇ヨ�山�广大���浣���缁�澧��跨��娴�����

     

    璁╂��浠�浣跨�ㄤ互涓�manifest�ㄤ袱涓�寰����′��村����Traefik锛�
     

    
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        traefik.ingress.kubernetes.io/service-weights: |
          animals-app: 99%
          animals-app-canary: 1%
      name: animals-app
    spec:
      rules:
      - http:
          paths:
          - backend:
              serviceName: animals-app
              servicePort: 80
            path: /
          - backend:
              serviceName: animals-app-canary
              servicePort: 80
            path: /

     
    璇锋敞��traefik.ingress.kubernetes.io/service-weights��娉ㄩ����疏浚���疏浚�河渠�娴���濡�浣��ㄦ��疏浚���绔����★�animals-app��animals-app-canary锛�涔��村������Traefik广大���99%���ㄦ�疯�锋�璺��卞��animals-app deployment������Pod锛�骞跺�1%���ㄦ�疯�锋�璺��卞��animals-app-canary deployment������Pod��

     

    瑕�浣挎�よ�剧疆姝e父宸ヤ�锛���瑕�婊¤冻涓�河渠��′欢锛�
     

  • �������″��绔�蹇�椤诲�变韩�稿����璺�寰���涓绘�恒��

  • 璺ㄦ���″��绔��变韩��璇锋��绘�板��昏�′负100锛���

  • �惧��姣��煎�璇ュ�ㄦ������绮惧害���村��锛�����Traefik����3涓�广大��颁���������
     

    �荤�

     
    濡�浣���瑙�锛�Ingress��广大�澶��ㄦ���璺��卞��Kubernetes��缇や腑�稿���绔����$��寮哄ぇ宸ュ�枫���ㄦ�山��浠ヤ娇��Kubernetes������璁稿�Ingress controller�ュ����Ingress���ㄦ����绋�涓�锛���浠����逛�缁�河渠�Traefik Ingress controller锛�璇ユ�у�跺�ㄦ�����轰���绉扮��璺��憋�璐�潘藉��琛′互��Ingress controller���朵�甯歌�浠诲�°��