我正在尝试在Google云引擎中设置traefik负载均衡器。 我的配置:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: traefik-ingress-controller
namespace: default
labels:
k8s-app: traefik-ingress-lb
spec:
replicas: 2
template:
metadata:
labels:
app: traefik-ingress-lb
name: traefik-ingress-lb
annotations:
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
spec:
terminationGracePeriodSeconds: 60
serviceAccountName: traefik-ingress-controller
volumes:
- name: config
configMap:
name: traefik-config
containers:
- image: traefik
name: traefik-ingress-lb
imagePullPolicy: Always
volumeMounts:
- mountPath: "/config"
name: "config"
ports:
- name: admin
containerPort: 8080
- name: http
containerPort: 80
#hostPort: 80
- name: https
containerPort: 443
args:
- --api
- --kubernetes
- --logLevel=DEBUG
---
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service
namespace: default
spec:
type: LoadBalancer
selector:
k8s-app: traefik-ingress-lb
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
- name: admin
protocol: TCP
port: 8080
Traefik ui:
apiVersion: v1
kind: Service
metadata:
name: traefik-web-ui
namespace: default
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- protocol: TCP
port: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
namespace: default
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: traefik-web-ui
servicePort: 8080
不幸的是,这不起作用。服务和Pod正在运行,没有错误。但是,当我尝试连接时,它正在无限加载(有趣的是ping有效)。 如果我将配置调整为使用hostPort,则它适用于一个Pod。永远不会创建另一个Pod,因为第一个Pod已使用hostPort(错误:pod无法容纳主机端口)。
那么如何解决此问题以在不使用妖怪的情况下使用多个Pod?
答案 0 :(得分:0)
如果需要将其连接到Google Cloud Load Balancer,则需要VM中的主机端口。发生的情况是Kubernetes可能在主机上为其提供了一个随机端口,但您的Google Cloud Load Balancer指向80。您可能想尝试在服务上为服务中的后端端口名称分配targetPort
。我认为您的情况就是http
或https
或admin
。
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service
namespace: default
spec:
type: LoadBalancer
selector:
k8s-app: traefik-ingress-lb
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
- name: https
protocol: TCP
port: 443
targetPort: https
- name: admin
protocol: TCP
port: 8080
targetPort: admin
希望有帮助!