您的位置 首页 linux 运维

基于helm工具部署traefik案例:

基于helm工具部署traefik案例:

1.添加helm仓库
[root@master231 traefik]# helm repo add traefik https://traefik.github.io/charts


	2.更新仓库
[root@master231 traefik]# helm repo update 

	3.拉取chart
[root@master231 traefik]# helm pull  traefik/traefik
[root@master231 traefik]# tar xf traefik-23.1.0.tgz 


	4.修改svc的类型,将默认的LoadBalancer改为NodePort
[root@master231 traefik]# vim traefik/values.yaml 
...
service:
  ...
  # type: LoadBalancer
  type: NodePort


	5.安装traefik
[root@master231 traefik]# helm install oldboyedu-traefik traefik

	6.暴露traefik的dashboard
[root@master231 traefik]# kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name) 9000:9000 --address 0.0.0.0


	7.访问dashboard
http://10.0.0.231:9000/dashboard/#/

参考链接:

https://doc.traefik.io/traefik/getting-started/install-traefik/#use-the-helm-chart

 

- ingress
	1.自定义svc的端口号
[root@master231 traefik]# pwd
/manifests/add-ons/traefik
[root@master231 traefik]# 
[root@master231 traefik]# cat traefik/templates/service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: oldboyedu-traefik
spec:
  ports:
  - name: web
    nodePort: 3080
    port: 80
    protocol: TCP
    targetPort: web
  - name: websecure
    nodePort: 3443
    port: 443
    protocol: TCP
    targetPort: websecure
  selector:
    app.kubernetes.io/instance: oldboyedu-traefik-default
    app.kubernetes.io/name: traefik
  type: NodePort
[root@master231 traefik]# 


	2.暴露服务
[root@master231 ingresses]# cat 01-deploy-apps/01-deploy-app01.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx-v1
  labels:
    apps: myweb
spec:
  replicas: 3
  selector:
    matchExpressions:
    - key: apps
      values: 
      - "v1"
      operator: In
  template:
    metadata:
      labels:
        apps: v1
        school: oldboyedu
    spec:
      containers:
      - name: v1
        image: harbor.oldboyedu.com/oldboyedu-apps/apps:v1

---

apiVersion: v1
kind: Service
metadata:
  name: apps-v1
spec:
  selector:
    apps: v1
  ports:
  - port: 80
    targetPort: 80
[root@master231 ingresses]# 
[root@master231 ingresses]# 
[root@master231 ingresses]# 
[root@master231 ingresses]# 
[root@master231 ingresses]# cat 01-deploy-apps/02-deploy-app02.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx-v2
  labels:
    apps: myweb
spec:
  replicas: 3
  selector:
    matchExpressions:
    - key: apps
      values: 
      - "v2"
      operator: In
  template:
    metadata:
      labels:
        apps: v2
        school: oldboyedu
    spec:
      containers:
      - name: v2
        image: harbor.oldboyedu.com/oldboyedu-apps/apps:v2

---

apiVersion: v1
kind: Service
metadata:
  name: apps-v2
spec:
  selector:
    apps: v2
  ports:
  - port: 80
    targetPort: 80
[root@master231 ingresses]# 
[root@master231 ingresses]# 
[root@master231 ingresses]# 
[root@master231 ingresses]# cat 01-deploy-apps/03-deploy-app03.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx-v3
  labels:
    apps: myweb
spec:
  replicas: 3
  selector:
    matchExpressions:
    - key: apps
      values: 
      - "v3"
      operator: In
  template:
    metadata:
      labels:
        apps: v3
        school: oldboyedu
    spec:
      containers:
      - name: v3
        image: harbor.oldboyedu.com/oldboyedu-apps/apps:v3

---

apiVersion: v1
kind: Service
metadata:
  name: apps-v3
spec:
  selector:
    apps: v3
  ports:
  - port: 80
    targetPort: 80
[root@master231 ingresses]# 
[root@master231 ingresses]# kubectl apply -f 01-deploy-apps/

	

	2.编写Ingress规则
[root@master231 ingresses]# cat 02-ing/02-ingress-apps.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: oldboyedu-ing-apps-all
  annotations:
    kubernetes.io/ingress.class: traefik  # 指定Ingress 控制器为"traefik"
spec:
  # 定义Ingress规则
  rules:
    # 访问的主机名
  - host: apps01.oldboyedu.com
    # 定义http的相关规则
    http:
      paths:
      - backend:
          service:
            name: apps-v1
            port:
              number: 80
        path: /
        pathType: Prefix
  - host: apps02.oldboyedu.com
    http:
      paths:
      - backend:
          service:
            name: apps-v2
            port:
              number: 80
        path: /
        pathType: Prefix
  - host: apps03.oldboyedu.com
    http:
      paths:
      - backend:
          service:
            name: apps-v3
            port:
              number: 80
        path: /
        pathType: Prefix
[root@master231 ingresses]# 
[root@master231 ingresses]# kubectl apply -f 02-ing


	3.查看Ingress的详细信息
[root@master231 ingresses]# kubectl describe ingress oldboyedu-ing-apps-all 
Name:             oldboyedu-ing-apps-all
Labels:           <none>
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                  Path  Backends
  ----                  ----  --------
  apps01.oldboyedu.com  
                        /   apps-v1:80 (10.100.1.214:80,10.100.2.226:80,10.100.2.227:80)
  apps02.oldboyedu.com  
                        /   apps-v2:80 (10.100.1.215:80,10.100.1.216:80,10.100.2.229:80)
  apps03.oldboyedu.com  
                        /   apps-v3:80 (10.100.1.217:80,10.100.1.218:80,10.100.2.228:80)
Annotations:            kubernetes.io/ingress.class: traefik
Events:                 <none>
[root@master231 ingresses]# 



	4.测试访问
[root@harbor250 ~]# curl -H "host: apps01.oldboyedu.com" 10.0.0.232:3080
<h1>oldboyedu apps01</h1>
[root@harbor250 ~]# 
[root@harbor250 ~]# 
[root@harbor250 ~]# curl -H "host: apps02.oldboyedu.com" 10.0.0.232:3080
<h1>oldboyedu apps02</h1>
[root@harbor250 ~]# 
[root@harbor250 ~]# curl -H "host: apps03.oldboyedu.com" 10.0.0.232:3080
<h1>oldboyedu apps03</h1>
[root@harbor250 ~]# 


	5.使用负载均衡器暴露服务基于https协议

5.使用负载均衡器暴露服务基于https协议、

可以用nginx 做转发:参考 https://www.baimeidashu.com/11507.html

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章