如何覆盖Quarkus kubernetes扩展中的服务和入口规则

u5rb5r59  于 2022-12-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(105)

我在www.example.com中设置了kubernetes资源application.properties

# Ingress
quarkus.kubernetes.expose=true
# service will be exposed
quarkus.kubernetes.ingress.expose=true
quarkus.kubernetes.ingress.host=k8s.cch.dev
quarkus.kubernetes.ingress.annotations."nginx.ingress.kubernetes.io/rewrite-target"=/$2
# quarkus.kubernetes.ingress.tls.${SECRET_NAME}.enabled=true
# quarkus.kubernetes.ingress.tls.${SECRET_NAME}.hosts=k8s.cch.dev
quarkus.kubernetes.ingress.rules.0.host=k8s.cch.dev
quarkus.kubernetes.ingress.rules.0.path=/api/v1(/|$)(.*)
quarkus.kubernetes.ingress.rules.0.path-type=Prefix
quarkus.kubernetes.ingress.rules.0.service-name=${quarkus.container-image.name}
quarkus.kubernetes.ingress.rules.0.service-port-name=http
quarkus.kubernetes.ingress.rules.0.service-port-number=${quarkus.kubernetes.ports.http.container-port:quarkus.http.port}

quarkus.kubernetes.ports.http.container-port=8080
quarkus.kubernetes.ports.http.path=/
quarkus.kubernetes.ports.http.protocol=tcp

但是入口不能覆盖默认的path: /

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.quarkus.io/commit-id: dbe06014c4986c544ed25fba97f96ac2cecc4091
    app.quarkus.io/build-timestamp: 2022-12-12 - 02:20:45 +0000
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  labels:
    app.kubernetes.io/name: kubernetes-with-quarkus
    app.kubernetes.io/part-of: kubernetes-with-quarkus
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
  name: kubernetes-with-quarkus
  namespace: prod
spec:
  rules:
    - host: k8s.cch.dev
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-quarkus
                port:
                  name: http
            path: /
            pathType: Prefix
          - backend:
              service:
                name: kubernetes-with-quarkus
                port:
                  name: http
            path: /api/v1(/|$)(.*)
            pathType: Prefix

如何将spec.ports.port更改为8080?我在kubernetes扩展上找不到配置。

apiVersion: v1
kind: Service
metadata:
  annotations:
    app.quarkus.io/commit-id: dbe06014c4986c544ed25fba97f96ac2cecc4091
    app.quarkus.io/build-timestamp: 2022-12-12 - 02:20:45 +0000
    prometheus.io/scrape: "true"
    prometheus.io/path: /q/metrics
    prometheus.io/port: "8080"
    prometheus.io/scheme: http
  labels:
    app.kubernetes.io/name: kubernetes-with-quarkus
    app.kubernetes.io/part-of: kubernetes-with-quarkus
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
  name: kubernetes-with-quarkus
  namespace: prod
spec:
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8080
  selector:
    app.kubernetes.io/name: kubernetes-with-quarkus
    app.kubernetes.io/part-of: kubernetes-with-quarkus
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
  type: ClusterIP
j9per5c4

j9per5c41#

您的配置将添加到入口规则,因为您指定了两个路径:

# ...
quarkus.kubernetes.ingress.rules.0.path=/api/v1(/|$)(.*)
# ...
quarkus.kubernetes.ports.http.path=/

Quarkus将尝试查找路径为“/API/v1(/)”的匹配入口规则|$)(.*)”,如果找不到,它将添加一个新的。
相反,如果您想要覆盖默认路径和服务矶钓,则只需添加以下两个属性:

quarkus.kubernetes.ports.http.host-port=<any other port>
quarkus.kubernetes.ports.http.path=/api/v1(/|$)(.*)

然后,如果要更改生成的入口规则,请用途:

quarkus.kubernetes.ingress.rules.0.path=/api/v1(/|$)(.*)
quarkus.kubernetes.ingress.rules.0.host or path-type or other ingress rule configuration

由于属性quarkus.kubernetes.ports...在如何与生成的Ingress资源相关方面不是非常直观,因此已经有计划对其进行改进:https://github.com/quarkusio/quarkus/issues/29279

相关问题