如何向 EKS 集群添加服务和 traefik 入口?

How do I add a service and traefik ingress to an EKS cluster?

备注

我正在尝试将演示服务(来自 'Kubernetes in Action')的服务和入口部署到安装了 Helm traefik 入口控制器的 AWS EKS 集群。

在我的本地 /etc/hosts 文件中将 traefik 提供的 AWS ELB 的 IP 地址手动添加到该主机名后,我能够从 traefik.example.com 主机名访问 traefik 仪表板.

如果我描述 traefik-dashboard 的服务和入口:

$ kubectl describe svc -n kube-system traefik-dashboard
Name:              traefik-dashboard
Namespace:         kube-system
Labels:            app=traefik
                   chart=traefik-1.52.6
                   heritage=Tiller
                   release=traefik
Annotations:       <none>
Selector:          app=traefik,release=traefik
Type:              ClusterIP
IP:                10.100.164.81
Port:              <unset>  80/TCP
TargetPort:        8080/TCP
Endpoints:         172.31.27.70:8080
Session Affinity:  None
Events:            <none>

$ kubectl describe ing -n kube-system traefik-dashboard
Name:             traefik-dashboard
Namespace:        kube-system
Address:
Default backend:  default-http-backend:80 (<none>)
Rules:
Host                 Path  Backends
----                 ----  --------
traefik.example.com
                        traefik-dashboard:80 (172.31.27.70:8080)
Annotations:
Events:  <none>

服务和入口控制器似乎正在使用 kube-system 命名空间中的 运行 traefik-575cc584fb-v4mfn pod。

根据此信息并查看 traefik 文档,我尝试使用以下 YAML 通过入口公开演示服务:

apiVersion: apps/v1beta2
kind: ReplicaSet
metadata:
name: kubia
spec:
replicas: 3
selector:
    matchLabels:
    app: kubia
template:
    metadata:
    labels:
        app: kubia
    spec:
    containers:
    - name: kubia
        image: luksa/kubia

---

apiVersion: v1
kind: Service
metadata:
name: kubia
namespace: default
spec:
selector:
    app: traefik
    release: traefik
ports:
- name: web
    port: 80
    targetPort: 8080

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kubia
namespace: default
spec:
rules:
- host: kubia.int
    http:
    paths:
    - path: /
        backend:
        serviceName: kubia
        servicePort: web

应用此后,在手动将 traefik 提供的 AWS ELB 的 IP 地址添加到该主机名后,我无法从 kubia.int 主机名访问 kubia 服务我的本地 /etc/hosts 文件。相反,我在响应中得到 Service Unavailable。描述创建的资源显示了一些不同的信息。

$ kubectl describe svc kubia
Name:              kubia
Namespace:         default
Labels:            <none>
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                    {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"kubia","namespace":"default"},"spec":{"ports":[{"name":"web","por...
Selector:          app=traefik,release=traefik
Type:              ClusterIP
IP:                10.100.142.243
Port:              web  80/TCP
TargetPort:        8080/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

$ kubectl describe ing kubia
Name:             kubia
Namespace:        default
Address:
Default backend:  default-http-backend:80 (<none>)
Rules:
Host       Path  Backends
----       ----  --------
kubia.int
            /   kubia:web (<none>)
Annotations:
kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"kubia","namespace":"default"},"spec":{"rules":[{"host":"kubia.int","http":{"paths":[{"backend":{"serviceName":"kubia","servicePort":"web"},"path":"/"}]}}]}}

Events:  <none>

我还注意到演示 kubia 服务没有端点,相应的入口显示没有可用的后端。

我注意到的另一件事是演示 kubia 服务和入口在 default 命名空间中,而 traefik-dashboard 服务和入口在 kube-system 命名空间中.

有没有人突然想到了什么?关于最佳诊断方法有什么建议吗?

非常感谢!

您似乎错过了告诉您的 Traefik 入口控制器为该入口定义服务的 kubernetes.io/ingress.class: traefik

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kubia
  namespace: default
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
rules:
- host: kubia.int
    http:
    paths:
    - path: /
        backend:
        serviceName: kubia
        servicePort: web

如果您查看 docs 中的示例,您会发现唯一没有注释的 Ingress 是指向 Traefik Web UI 的 traefik-web-ui