我在Google Cloud Platform中创建了一个kubernetes集群,此后,我在集群上安装了Helm / tiller,然后像正式文档所述那样安装了带头盔的traefik。
现在,我正在尝试为服务创建一个Ingress,但是如果我添加注释kubernetes.io/ingress.class: traefik
,则不会创建Ingress的负载平衡器。
但是没有注释,它可以与默认的Ingress一起使用。
(服务类型为节点端口)
编辑:我还在干净的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
服务已创建,但未创建入口负载均衡器:
但是,如果我删除行kubernetes.io/ingress.class: traefik
,它将适用于Kubernetes的默认入口
答案 0 :(得分:1)
您可以尝试如下添加更多注释
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
traefik.ingress.kubernetes.io/redirect-entry-point: https
traefik.ingress.kubernetes.io/redirect-permanent: "true"
喜欢这个
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-dashboard-ingress
namespace: traefik
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
traefik.ingress.kubernetes.io/redirect-entry-point: https
traefik.ingress.kubernetes.io/redirect-permanent: "true"
spec:
rules:
- host: traefik-ui.example.com
http:
paths:
- path: /
backend:
serviceName: traefik-dashboard
servicePort: 8080
答案 1 :(得分:1)
Traefik默认情况下不会为您创建负载均衡器。
HTTP(s) load balancing with Ingress文档中提到:
创建Ingress对象时,GKE入口控制器将创建 Google Cloud Platform HTTP(S)负载均衡器并对其进行配置 根据Ingress及其关联的信息 服务。
这全部适用于GKE入口控制器(gce)-有关gce的更多信息,您可以在这里找到:https://github.com/kubernetes/ingress-gce
如果您想使用Traefik作为入口-您必须使用type: LoadBalancer
公开Traefik服务
示例:
apiVersion: v1
kind: Service
metadata:
name: traefik
spec:
type: LoadBalancer
selector:
k8s-app: traefik-ingress-lb
ports:
- port: 80
targetPort: 80
更多信息,其中包含许多说明图和实际工作示例,您可以在Exposing Kubernetes Services to the internet using Traefik Ingress Controller文章中找到。
希望获得帮助。