Ingress-Nginx高可用


以最新版的nginx-ingress-controller:0.30.0為例 

高可用Ingress 架構如下:

 

打開 https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/mandatory.yaml 然后Raw下載mandatory.yaml,修改其中的 nginx-ingress-controller 部分,也就是官網上的 with-rbac.yaml

1、修改Deployment為DaemonSet,並注釋掉副本數

2、啟用hostNetwork網絡,並指定運行節點

hostNetwork暴露ingress-nginx controller的相關業務端口到主機,這樣node節點主機所在網絡的其他主機,都可以通過該端口訪問到此應用程序。

nodeSelector指定之前添加ingress-controller=true標簽的node

3、修改鏡像地址

4、增加master節點容忍(可選)

tolerations: #增加容忍,可分配到master節點
- key: "node-role.kubernetes.io/master"
  operator: "Exists"
  effect: "NoSchedule"

 

修改完成后:

apiVersion: apps/v1
#kind: Deployment
kind: DaemonSet
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
  labels:
    k8s-app: ingress-controller
spec:
  #replicas: 1
  selector:
    matchLabels:
      k8s-app: ingress-controller
  template:
    metadata:
      labels:
        k8s-app: ingress-controller
      annotations:
        prometheus.io/port: "10254"
        prometheus.io/scrape: "true"
    spec:
      # wait up to five minutes for the drain of connections
      terminationGracePeriodSeconds: 300
      serviceAccountName: nginx-ingress-serviceaccount
      hostNetwork: true
      nodeSelector:
        ingress-controller: "true"
      tolerations: #增加容忍,可分配到master節點
        - key: "node-role.kubernetes.io/master"
          operator: "Exists"
          effect: "NoSchedule"
      containers:
        - name: nginx-ingress-controller
          image: registry-vpc.cn-beijing.aliyuncs.com/base/nginx-ingress-controller:0.30.0
          args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
            - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
            - --publish-service=$(POD_NAMESPACE)/ingress-nginx
            - --annotations-prefix=nginx.ingress.kubernetes.io
          securityContext:
            allowPrivilegeEscalation: true
            capabilities:
              drop:
                - ALL
              add:
                - NET_BIND_SERVICE
            # www-data -> 101
            runAsUser: 101
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: 80
              #protocol: TCP
            - name: https
              containerPort: 443 #protocol: TCP
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          lifecycle:
            preStop:
              exec:
                command:
                  - /wait-shutdown

 

節點打標簽:

# kubectl label node master-92 ingress-controller="true"

此時再使用keepalived或外部slb進行高可用設置即可。

 

參考資料:https://www.cnblogs.com/keep-live/p/11882829.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM