kubernetes集群traefik ingress實現同一命名空間不同微服務模塊的訪問
阿新 • • 發佈:2019-04-22
xwiki 設置 traefik 技術分享 pull end point ron template 背景:kubernetes集群traefik ingress實現同一命名空間不同微服務模塊的訪問
1.安裝traefik ingress
1.安裝traefik ingress
cat > traefik-ingress.yaml <<EOF kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: traefik-ingress-controller rules: - apiGroups: - "" resources: - pods - services - endpoints - secrets verbs: - get - list - watch - apiGroups: - extensions resources: - ingresses verbs: - get - list - watch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: traefik-ingress-controller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: traefik-ingress-controller subjects: - kind: ServiceAccount name: traefik-ingress-controller namespace: c7n-system --- apiVersion: v1 kind: ServiceAccount metadata: name: traefik-ingress-controller namespace: c7n-system --- kind: Deployment apiVersion: apps/v1beta1 metadata: name: traefik-ingress-controller namespace: c7n-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-controller terminationGracePeriodSeconds: 60 containers: - image: traefik:v1.7.4 imagePullPolicy: IfNotPresent name: traefik-ingress-lb args: - --api - --kubernetes - --logLevel=INFO --- kind: Service apiVersion: v1 metadata: name: traefik-ingress-service namespace: c7n-system spec: selector: k8s-app: traefik-ingress-lb ports: - protocol: TCP # 該端口為 traefik ingress-controller的服務端口 port: 80 # 集群hosts文件中設置的 NODE_PORT_RANGE 作為 NodePort的可用範圍 # 從默認20000~40000之間選一個可用端口,讓ingress-controller暴露給外部的訪問 nodePort: 23456 name: web - protocol: TCP # 該端口為 traefik 的管理WEB界面 port: 8080 name: admin type: NodePort EOF
2.查看k8s集群配置微服務svc
3.配置raefik ingress後端f服務
cat > traefik-choerodon.yaml <<EOF --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: choerodon-xiongxj namespace: c7n-system spec: rules: - host: choerodon.maimailoan.cn http: paths: - path: /api-gateway backend: serviceName: api-gateway servicePort: 8080 - path: /c7n-slaver backend: serviceName: c7n-slaver servicePort: 80 - path: /chartmuseum-chartmuseum backend: serviceName: chartmuseum-chartmuseum servicePort: 8080 - path: /choerodon-front backend: serviceName: choerodon-front servicePort: 80 - path: /config-server backend: serviceName: config-server servicePort: 8010 - path: /devops-service backend: serviceName: devops-service servicePort: 8060 - path: /gitlab backend: serviceName: gitlab servicePort: 80 - path: /harbor backend: serviceName: harbor-harbor-ui servicePort: 80 - path: /minio backend: serviceName: minio-svc servicePort: 9000 - path: /xwiki backend: serviceName: xwiki servicePort: 8080 EOF
4.查看ingress詳情
5.訪問
kubernetes集群traefik ingress實現同一命名空間不同微服務模塊的訪問