k8s-traefik默认80端口
vim traefik.yaml
kind: Deployment apiVersion: extensions/v1beta1 metadata: name: traefik-ingress-controller namespace: kube-ops 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 tolerations: - operator: "Exists" nodeSelector: kubernetes.io/hostname: master containers: - image: traefik name: traefik-ingress-lb imagePullPolicy: IfNotPresent ports: - name: http hostPort: 80 containerPort: 80 - name: admin hostPort: 8580 containerPort: 8580 args: # - --api - --web - --web.address=:8580 - --kubernetes - --logLevel=INFO --- kind: Service apiVersion: v1 metadata: name: traefik-ingress-service namespace: kube-ops spec: selector: k8s-app: traefik-ingress-lb #type: NodePort ports: - name: web port: 80 targetPort: 8580
给traefik授权认证!
vim rbac.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: traefik-ingress-controller namespace: kube-ops --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: traefik-ingress-controller rules: - apiGroups: - "" resources: - services - endpoints - secrets verbs: - get - list - watch - apiGroups: - extensions resources: - ingresses verbs: - get - list - watch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 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: kube-ops
创建ingress对象:
vim ingress.yaml
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: traefik-web-ui namespace: kube-ops annotations: kubernetes.io/ingress.class: traefik spec: rules: - host: traefik.ui.com http: paths: - backend: serviceName: traefik-ingress-service servicePort: web