這里提示一下: 前端入口代理為后端Service的Service
問:ingress里的service是哪個(gè)service逛艰,怎么寫
答:還是以下面這個(gè)對(duì)象為例赛惩,可以看到哀墓,這個(gè)service寫的是traefikminio,實(shí)際上也就是minio的pod的部署svc yaml里的service的名字喷兼,也就是minio-svc.yaml這個(gè)定義Service kind類型為Service的metadata下面name的名字篮绰,端口實(shí)際上就是你想讓此條ingress規(guī)則代理的域名被轉(zhuǎn)發(fā)到service所對(duì)應(yīng)的pod的哪個(gè)端口上,這也就解釋了為什么即使是https的時(shí)候這個(gè)地方寫的仍然是8080端口季惯,因?yàn)榇艘?guī)則的entryPoints字段的websecure才是流量入口吠各,而8080是實(shí)際訪問的地址
cd /root/hero/app/yaml/ingress/traefik-contrain-80-443/
mkdir ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=tts.herotest.com.cn" #查看生成的兩個(gè)文件
kubectl create secret tls https --cert=tls.crt --key=tls.key -n hpc #在hpc的命名空間里面設(shè)置secret
kubectl get secret -n hpc #查看hpc命名空間中發(fā)現(xiàn)https已經(jīng)成功被創(chuàng)建了
前端代理配置如下:
[root@allinone traefik-contrain-80-443]# cat traefik-miniossl.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
? name: miniossl
? namespace: hpc
spec:
? entryPoints:
? ? - websecure #前端入口: 名稱要和traefik-deploy.yaml里面的ports下面的name名稱要一致
? routes:
- match: Host(`tts.herotest.com.cn`) && PathPrefix(`/`)
? ? kind: Rule
? ? services:
? ? - name: traefikminio #要和后端minio-svc.yaml配置文件中的name字段一致 ,前端入口代理為后端Service的Service
? ? ? port: 9000
? tls:
? ? secretName: https
-----------------------------------
traefik-deploy文件配置如下勉抓,entrypoints定義了80和443的入口
[root@allinone traefik-contrain-80-443]# cat traefik-deploy.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
? namespace: default
? name: traefik-ingress-controller
---
kind: Deployment
apiVersion: apps/v1
metadata:
? namespace: default
? name: traefik
? labels:
? ? app: traefik
spec:
? replicas: 2
? selector:
? ? matchLabels:
? ? ? app: traefik
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: traefik
? ? spec:
? ? ? serviceAccountName: traefik-ingress-controller
? ? ? containers:
? ? ? ? - name: traefik
? ? ? ? ? image: traefik:v2.0.2
? ? ? ? ? args:
? ? ? ? ? ? - --api.insecure
? ? ? ? ? ? - --accesslog
? ? ? ? ? ? - --entrypoints.web.Address=:80
? ? ? ? ? ? - --entrypoints.websecure.Address=:443
? ? ? ? ? ? - --providers.kubernetescrd
? ? ? ? ? ? - --certificatesresolvers.default.acme.tlschallenge
- --certificatesresolvers.default.acme.email=foo@you.com
? ? ? ? ? ? - --certificatesresolvers.default.acme.storage=acme.json
? ? ? ? ? ? # Please note that this is the staging Let's Encrypt server.
? ? ? ? ? ? # Once you get things working, you should remove that whole line altogether.
- --certificatesresolvers.default.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
? ? ? ? ? ports:
? ? ? ? ? ? - name: web
? ? ? ? ? ? ? containerPort: 80
? ? ? ? ? ? - name: websecure
? ? ? ? ? ? ? containerPort: 443
? ? ? ? ? ? - name: admin
? ? ? ? ? ? ? containerPort: 8080
----------------------
[root@allinone minio3]# cat minio.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
? name: traefikminio
? namespace: hpc
spec:
? replicas: 1
? selector:
? ? matchLabels:
app: traefikminio#標(biāo)簽選擇器走孽,后面minio-svc.yaml selector下面要配置app: traefikminio? serviceName: traefikminio
serviceName: traefikminio
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: traefikminio
? ? ? ? serviceName: traefikminio
? ? spec:
? ? ? containers:
? ? ? - name: traefikminio
? ? ? ? image: 172.88.19.131/hero/myminio-entry:v1
---------------------------
[root@allinone minio3]# cat minio-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: traefikminio#這個(gè)name 在配置traefik-miniossl.yaml前端入口services下的name字段也要配置traefikminio 這個(gè)名稱
? namespace: hpc
spec:
? ports:
? - name: traefikminio
? ? port: 9000
? ? protocol: TCP
? ? targetPort: 9000
? selector:
app: traefikminio? #通過標(biāo)簽選擇器關(guān)聯(lián)后端的一組pod
? ? serviceName: traefikminio? #通過標(biāo)簽選擇器關(guān)聯(lián)后端的一組pod
kubectl apply -f traefik-miniossl.yaml
kubectl get ingressroute -n hpc #發(fā)現(xiàn)miniossl IngressRoute前端代理名稱已經(jīng)在里面了
kubectl describe ingressroute miniossl -n hpc? #已經(jīng)走h(yuǎn)ttps協(xié)議了
登陸traefik控制臺(tái)查看,發(fā)現(xiàn)已經(jīng)走h(yuǎn)ttps協(xié)議了琳状,配置https域名成功
我們來打開瀏覽器通過https訪問下域名上試試
在本機(jī)配置host
192.168.19.131 tts.herotest.com.cn
https://tts.herotest.com.cn:30443#成功訪問