Ingress资源规范


k8s v1.19版本中Ingress资源规范从v1beta1版本升级至稳定的v1版本

v1beta1版本

v1beta1版本的Ingress资源位于API群组的extensions之中,该版本的资源规范可用的字段及其简要说明如下:

示例文件:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-demo
  annotations:
    kubernetes.io/ingress.class: "nginx"
  namespace: dev
spec:
  rules:
  - host: www.ik8s.io
    http:
      paths:
      - path: 
        backend:
          serviceName: ik8s
          servicePort: 80
  - host: www.ilinux.io
    http:
      paths:
      - path: /foo 
        backend:
          serviceName: foo-svc
          servicePort: 80
      - path: /bar 
        backend:
          serviceName: bar-svc
          servicePort: 8080
  tls:
  - hosts:
    - www.ik8s.io
    secretName: tls-ik8s
  backend:
    serviceName: default-backend
    servicePort: 80

v1版本

v1版本的Ingress资源位于API群组的networking.k8s.io之中,该版本的资源规范与v1beta1版本的主要区别在spec.rules.http.backend的内嵌字段上,该版本的资源规范可用的字段及其简要说明如下:

示例文件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-demo
  annotations:
    kubernetes.io/ingress.class: "nginx"
  namespace: dev
spec:
  rules:
  - host: www.ik8s.io
    http:
      paths:
      - path: /
        pathType: Prefix 
        backend:
          service:
            name: ik8s
            port:
              number: 80
  - host: www.ilinux.io
    http:
      paths:
      - path: /foo 
        pathType: Prefix
        backend:
          service:
            name: foo-svc
            port:
              number: 80
      - path: /bar 
        pathType: Prefix
        backend:
          service:
            name: bar-svc
            port: 
              number: 8080