gke上的traefik设置无法正常运行

时间:2018-07-15 23:26:41

标签: kubernetes traefik kubernetes-ingress google-kubernetes-engine

我正在尝试按照用户指南(https://docs.traefik.io/user-guide/kubernetes/)在GKE中运行traefik

我没有看到仪表板,而是得到了404。我想RBAC设置存在问题,但我无法解决。

任何帮助将不胜感激。

入口控制器日志显示恒定流量(每秒一个):

  

E0714 12:19:56.665790 1Reflector.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1.Service:服务被禁止:用户   “系统:serviceaccount:kube系统:traefik-ingress-controller”不能   列出群集范围内的服务:未知用户   “系统:serviceaccount:kube-system:traefik-ingress-controller”

traefik吊舱本身不断涌出:

  

E0714 12:17:45.108356 1Reflector.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1beta1.Ingress:禁止ingresses.extensions:   用户“ system:serviceaccount:default:default”无法列出   命名空间“ kube-system”中的ingresses.extensions:未知用户   “ system:serviceaccount:default:default”

     

E0714 12:17:45.708160 1 Reflections.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1.Service:服务被禁止:用户   “ system:serviceaccount:default:default”无法在   名称空间“默认”:未知用户   “ system:serviceaccount:default:default”

     

E0714 12:17:45.714057 1 Reflections.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1.Endpoints:禁止使用端点:用户   “ system:serviceaccount:default:default”无法在   命名空间“ kube-system”:未知用户   “ system:serviceaccount:default:default”

     

E0714 12:17:45.714829 1 Reflections.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1beta1.Ingress:禁止ingresses.extensions:   用户“ system:serviceaccount:default:default”无法列出   名称空间“默认”中的ingresses.extensions:未知用户   “ system:serviceaccount:default:default”

     

E0714 12:17:45.715653 1 Reflections.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1.Endpoints:禁止使用端点:用户   “ system:serviceaccount:default:default”无法在   名称空间“默认”:未知用户   “ system:serviceaccount:default:default”

     

E0714 12:17:45.716659 1Reflector.go:205]   github.com/containous/traefik/vendor/k8s.io/client-go/informers/factory.go:86:   无法列出* v1.Service:服务被禁止:用户   “ system:serviceaccount:default:default”无法在   命名空间“ kube-system”:未知用户   “ system:serviceaccount:default:default”

我使用以下方法创建了簇角色:

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: traefik-ingress-controller
rules:
  - apiGroups: [""]
    resources: ["servies", "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: kube-system

,然后将traefik部署为部署:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: traefik-ingress-controller
  namespace: kube-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
        name: traefik-ingress-lb
        ports:
        - name: http
          containerPort: 80
        - name: admin
          containerPort: 8080
        args:
        - --api
        - --kubernetes
        - --logLevel=INFO
---
kind: Service
apiVersion: v1
metadata:
  name: traefik-ingress-service
  namespace: kube-system
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - protocol: TCP
      port: 80
      name: web
    - protocol: TCP
      port: 8080
      name: admin
  type: LoadBalancer

在使用头盔安装traefik时,我使用了以下值文件:

dashboard:
  enabled: true
  domain: traefik.example.com
kubernetes:
  namespaces:
    - default
    - kube-system

最后,对于UI,我使用了以下yaml:

---
apiVersion: v1
kind: Service
metadata:
  name: traefik-web-ui
  namespace: kube-system
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
  - name: web
    port: 80
    targetPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traefik-web-ui
  namespace: kube-system
spec:
  rules:
  - host: traefik.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: traefik-web-ui
          servicePort: web

感谢您的光临!

(编辑:标题中的错字)

2 个答案:

答案 0 :(得分:2)

由于名称空间“ kube-system”是由主节点处理的,因此您将无法在该特定名称空间上部署任何内容。 GKE内的“主”节点是一项托管服务,目前用户无法访问。

如果您想拥有此功能,那么我目前只能提供的建议是创建自己的custom cluster from scratch。这样一来,您就可以访问主节点,并且可以根据自己的喜好自定义集群。

编辑:我能够从github中找到有关如何将Traefik用作GKE负载平衡器的说明。我建议先在生产集群中运行它之前对其进行测试。

答案 1 :(得分:1)

我认为您的问题是您正在设置名称为“ traefik-ingress-controller”和名称空间为“ kube-system”的ClusterRoleBinding,但是Traefik在默认的名称空间中使用serviceaccount默认运行。

尝试将您的ClusterRoleBinding更改为:

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: default
 namespace: default

或使用服务帐户“ traefik-ingress-controller”和名称空间“ kube-system”部署系统