温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Kubernetes Ingress does not work with traefisk

其他 - Kubernetes Ingress不适用于traefisk

发布于 2020-03-27 10:47:48

我在Google Cloud Platform中创建了一个kubernetes集群,此后,我在集群上安装了Helm / tiller,然后,像官方文档所说的那样,在traefik上安装了helm。

现在,我正在尝试为服务创建一个Ingress,但是如果我添加注释kubernetes.io/ingress.class: traefik,则不会创建Ingress的负载平衡器。但是没有注释,它可以与默认的Ingress一起使用。(服务类型为nodeport)

编辑:我也在干净的Google Cloud kubernetes集群中尝试了这个示例:https ://supergiant.io/blog/using-traefik-as-ingress-controller-for-your-kubernetes-cluster/ 但当我选择kubernetes.io/ingress.class: traefik,将不会为入口创建负载均衡器。

我的文件是: animals-svc.yaml:

---
apiVersion: v1
kind: Service
metadata:
  name: bear
spec:
  type: NodePort
  ports:
  - name: http
    targetPort: 80
    port: 80
  selector:
    app: animals
    task: bear
---
apiVersion: v1
kind: Service
metadata:
  name: moose
spec:
  type: NodePort
  ports:
  - name: http
    targetPort: 80
    port: 80
  selector:
    app: animals
    task: moose
---
apiVersion: v1
kind: Service
metadata:
  name: hare
  annotations:
    traefik.backend.circuitbreaker: "NetworkErrorRatio() > 0.5"
spec:
  type: NodePort
  ports:
  - name: http
    targetPort: 80
    port: 80
  selector:
    app: animals
    task: hare

animals-ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: animals
  annotations:
    kubernetes.io/ingress.class: traefik
    # kubernetes.io/ingress.global-static-ip-name: "my-reserved-global-ip"
    # traefik.ingress.kubernetes.io/frontend-entry-points: http
    # traefik.ingress.kubernetes.io/redirect-entry-point: http
    # traefik.ingress.kubernetes.io/redirect-permanent: "true"
spec:
  rules:
  - host: hare.minikube
    http:
      paths:
      - path: /
        backend:
          serviceName: hare
          servicePort: http
  - host: bear.minikube
    http:
      paths:
      - path: /
        backend:
          serviceName: bear
          servicePort: http
  - host: moose.minikube
    http:
      paths:
      - path: /
        backend:
          serviceName: moose
          servicePort: http

animals-deployment.yaml:

---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: bear
  labels:
    app: animals
    animal: bear
spec:
  replicas: 2
  selector:
    matchLabels:
      app: animals
      task: bear
  template:
    metadata:
      labels:
        app: animals
        task: bear
        version: v0.0.1
    spec:
      containers:
      - name: bear
        image: supergiantkir/animals:bear
        ports:
        - containerPort: 80
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: moose
  labels:
    app: animals
    animal: moose
spec:
  replicas: 2
  selector:
    matchLabels:
      app: animals
      task: moose
  template:
    metadata:
      labels:
        app: animals
        task: moose
        version: v0.0.1
    spec:
      containers:
      - name: moose
        image: supergiantkir/animals:moose
        ports:
        - containerPort: 80
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: hare
  labels:
    app: animals
    animal: hare
spec:
  replicas: 2
  selector:
    matchLabels:
      app: animals
      task: hare
  template:
    metadata:
      labels:
        app: animals
        task: hare
        version: v0.0.1
    spec:
      containers:
      - name: hare
        image: supergiantkir/animals:hare
        ports:
        - containerPort: 80

服务已创建,但未创建入口负载均衡器:

enter image description here

但是,如果我删除该行,kubernetes.io/ingress.class: traefik它将与Kubernetes的默认入口一起使用

查看更多

查看更多

提问者
Rui Martins
被浏览
67
VKR 2019-07-03 22:04

默认情况下,Traefik不会为您创建负载平衡器。

作为HTTP和Ingress文档的负载平衡,请提及:

创建Ingress对象时,GKE入口控制器将创建Google Cloud Platform HTTP(S)负载均衡器,并根据Ingress及其相关服务中的信息进行配置。

这一切都适用于GKE入口控制器(gce)-有关gce的更多信息,您可以在这里找到:https : //github.com/kubernetes/ingress-gce

如果您想使用Traefik作为入口-您必须使用以下方法公开Traefik服务: type: LoadBalancer

例:

apiVersion: v1
kind: Service
metadata:
  name: traefik
spec:
  type: LoadBalancer
  selector:
    k8s-app: traefik-ingress-lb
  ports:
  - port: 80
    targetPort: 80

您可以在使用Traefik Ingress Controller将Kubernetes服务公开到Internet中找到更多信息,其中包含大量解释图和实际工作示例

希望对您有所帮助。

发布
问题

分享
好友

手机
浏览

扫码手机浏览