有人可以解释一下这个 K8s 入口文件吗

Can someone explain this K8s ingress file

我遇到了这个 ingress 文件并且很难理解这个 ingress 文件中的 http (& , *) 含义-有人可以解释一下 * 和 & 的含义吗?

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
  name: my-example
spec:
  rules:
  - host: example.com
    http: &exampleBackendService
      paths:
      - backend:
          serviceName: my-example
          servicePort: 80
        path: /
  - host: example-dev.com
    http: *exampleBackendService

都是yaml语法,k8s没有。参见 Anchors and Aliases, or a simpler tutorial
目的是重用、更短、可维护。

可以使用python(多选)展开:

import yaml


class ExplicitDumper(yaml.SafeDumper):
    def ignore_aliases(self, data):
        return True


d = yaml.safe_load('''your very long yaml string''')
print(yaml.dump(d, Dumper=ExplicitDumper))

输出

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
  name: my-example
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: my-example
          servicePort: 80
        path: /
  - host: example-dev.com
    http:
      paths:
      - backend:
          serviceName: my-example
          servicePort: 80
        path: /