使用 Kubernetes / Traefik 为我的本地应用程序创建一个本地域 rgpd.local

have a local domain rgpd.local for my local app with Kubernetes / Traefik

现在,我可以测试我的本地应用程序:http://localhost/rgpd/api/...

这是我的 rgpd-ingress.yaml

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: rgpd-ingress
  namespace: rgpd
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - http:
      paths:
      - path: /rgpd/api
        backend:
          serviceName: rgpd-api-local
          servicePort: "rgpd-port"

我想改成:rgpd.local

所以我改成了:

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: rgpd-ingress
  namespace: rgpd
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: rgpd.local
    http:
      paths:
      - backend:
         serviceName: rgpd-api-local
         servicePort: "port-rgpd"

但是现在,如果我输入旧的 url,我会得到 404 并且我也无法连接新的。

这是我的文件:

部署:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    reloader.stakater.com/auto: "true"
  labels:
    app: rgpd-api-local
  name: rgpd-api-local
  namespace: rgpd
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: rgpd-api-local
    spec:
      containers:
        - image: rgpd_api:local
          envFrom:
            - secretRef:
                name: rgpd-env
          name: rgpd-api-local
          ports:
            - containerPort: 10000

和服务:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rgpd-api-local
  name: rgpd-api-local
  namespace: rgpd
spec:
  type: NodePort
  ports:
  - name: "rgpd-port"
    port: 10000
  selector:
    app: rgpd-api-local

为什么不能用?

在主机文件中添加一个条目: /etc/hosts rgpd.local 127.0.0.1

更新 /etc/hosts 或仅提供主机 header 即 curl -H "Host: rgpd.local" 127.0.0.1