安全套接字層 (SSL) 證書(有時稱爲數字證書)用於在瀏覽器或用戶計算機與服務器或網站之間創建加密鏈接。SSL 鏈接可保護在每次訪問(稱爲會話)期間交換的敏感數據(例如信用卡信息),以防被非受權方攔截。SSL 鏈接可保護在每次訪問(稱爲會話)期間交換的敏感數據(例如信用卡信息),以防被非受權方攔截。前端
traefik 轉發或者提供的域名都可以支持https 請求!node
K8s 集羣
阿里雲dns帳戶:(須要讀寫dns服務)
ALICLOUD_ACCESS_KEY
ALICLOUD_SECRET_KEYweb
--- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: traefik-outer-ingress-controller rules: - apiGroups: - "" resources: - services - endpoints - secrets verbs: - get - list - watch - apiGroups: - extensions resources: - ingresses verbs: - get - list - watch - apiGroups: - extensions resources: - ingresses/status verbs: - update --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: traefik-outer-ingress-controller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: traefik-outer-ingress-controller subjects: - kind: ServiceAccount name: traefik-outer-ingress-controller namespace: kube-system
注意: 全部須要啓動traefik的節點配置標籤以下
traefik: "traefik-outer"json
--- apiVersion: v1 kind: ServiceAccount metadata: name: traefik-outer-ingress-controller namespace: kube-system --- kind: DaemonSet apiVersion: extensions/v1beta1 metadata: name: traefik-outer-ingress-controller namespace: kube-system labels: k8s-app: traefik-outer-ingress-lb spec: selector: matchLabels: k8s-app: traefik-outer-ingress-lb template: metadata: labels: k8s-app: traefik-outer-ingress-lb name: traefik-outer-ingress-lb spec: serviceAccountName: traefik-outer-ingress-controller terminationGracePeriodSeconds: 60 hostNetwork: true containers: - image: traefik:1.7.19 name: traefik-outer-ingress-lb env: - name: ALICLOUD_ACCESS_KEY # 添加環境變量ALICLOUD_ACCESS_KEY value: LTAIxxxxxxxxxxxAYfXqk # 阿里雲RAM帳號的access_key - name: ALICLOUD_SECRET_KEY # 添加環境變量ALICLOUD_SECRET_KEY value: gfNxxxxxxxxxxxoOslfc # 阿里雲RAM帳號的access_secret resources: limits: cpu: 1000m memory: 1024Mi requests: cpu: 1000m memory: 1024Mi ports: - name: http containerPort: 80 hostPort: 80 - name: https containerPort: 443 hostPort: 443 - name: admin containerPort: 8080 hostPort: 8080 args: - --api - --kubernetes - --configfile=/traefik.toml - --insecureskipverify #若是後端服務是https協議時不驗證其證書 - --logLevel=INFO #日誌級別 - --defaultEntryPoints=http,https #traefik同時開啓HTTP和HTTPS服務 - --entrypoints=Name:https Address::443 TLS #HTTPS服務監聽在443端口 - --entrypoints=Name:http Address::80 #HTTPS服務監聽在443端口,與http跳轉https配置衝突,只能配置一項; # - --entrypoints=Name:http Address::80 Redirect.EntryPoint:https #HTTP監聽在80端口,並將流量重定向至https - --acme #開啓證書驗證 - --acme.email=kevin@ptcpt.com #用於註冊的郵箱地址 - --acme.storage=/tmp/acme.json #證書申請臨時文件存儲位置 - --acme.acmeLogging=true #打開日誌,方便排錯 - --acme.entryPoint=https #證書類型,必需指向到一個443端口 - --acme.httpchallenge.entrypoint=http # 驗證域名時使用的協議 - --acme.dnschallenge # 域名驗證方式 - --acme.dnschallenge.provider=alidns # 域名提供商 - --acme.dnschallenge.delaybeforecheck=5 # 驗證域名延時 - --acme.onHostRule=true #自動爲acme.entryPoint下的新域名申請證書 - --acme.domains=ptmind.com #要申請證書的域名 - --acme.domains=lingxi365.cn #要申請證書的域名 - --acme.domains=lingxi.link #要申請證書的域名 nodeSelector: traefik: "traefik-outer" --- kind: Service apiVersion: v1 metadata: name: traefik-outer-ingress-service namespace: kube-system spec: selector: k8s-app: traefik-outer-ingress-lb ports: - protocol: TCP port: 80 name: web - protocol: TCP port: 443 name: https - protocol: TCP port: 8080 name: admin --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: traefik-outer-web-ui namespace: kube-system spec: rules: - host: traefik.ptmind.com #配置管理頁面的域名 http: paths: - path: / backend: serviceName: traefik-outer-ingress-service servicePort: admin
--api --kubernetes --configfile=/traefik.toml --insecureskipverify --logLevel=INFO \ --defaultEntryPoints=http,https '--entrypoints=Name:https Address::443 TLS' \ '--entrypoints=Name:http Address::80' --acme --acme.dnschallenge --acme.email=kevin@ptcpt.com \ --acme.storage=/tmp/acme.json --acme.acmeLogging=true --acme.entryPoint=https --acme.httpchallenge.entrypoint=http \ --acme.dnschallenge.provider=alidns --acme.dnschallenge.delaybeforecheck=5 \ --acme.domains=ptmind.com --acme.domains=lingxi365.cn --acme.domains=lingxi.link \ --acme.onHostRule=true
entryPoint = "https" # 啓用按需證書。若是這個主機名尚未證書,這將會在與一個主機名發起請求的第一個TLS握手中向Let's Encrypt請求一個證書。 # 警告,第一次在請求中獲取主機證書會致使TLS握手會很是慢,這會引發Dos***。 # 警告,值得注意的是Let's Encrypt是有請求上限的:https://letsencrypt.org/docs/rate-limits onDemand = false # 啓用根據前端Host規則來生成證書。這將會爲每一個具備Host規則的前端生成一個Let's Encrypt的證書。 # 舉個例子,一個具備規則的Host:test1.traefik.cn,test2.traefik.cn 將會爲主域名test1.traefik.cn與SAN(替代域名) test2.traefik.cn生成一個證書。 onHostRule = true [acme.httpChallenge] entryPoint="http"