# Requires the order namespace, the remote-provider GatewayClass elb-proxy-aws,
# and Services api-blue and api-green serving TLS on Service port 8443.
# Provision TLS Secrets (tls.crt, tls.key) and CA ConfigMaps (ca.crt) in order.
# Both backend servers must require and verify the Gateway's client certificate.
# Replace the example IAM role ARN before creating this separate private Gateway.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata: {name: orders-mtls, namespace: order}
spec:
  gatewayClassName: elb-proxy-aws
  listeners:
    - name: https
      hostname: orders.example.com
      protocol: HTTPS
      port: 443
      tls:
        mode: Terminate
        certificateRefs: [{group: "", kind: Secret, name: orders-server-tls}]
      allowedRoutes: {namespaces: {from: Same}}
  tls:
    frontend:
      default:
        validation:
          mode: AllowValidOnly
          caCertificateRefs: [{group: "", kind: ConfigMap, name: edge-client-ca}]
    backend:
      clientCertificateRef: {group: "", kind: Secret, name: orders-gateway-client}
---
apiVersion: gateway.elbproxy.aws/v1alpha1
kind: ELBProxyConfiguration
metadata: {name: orders-mtls-private, namespace: order}
spec:
  targetRefs: [{group: gateway.networking.k8s.io, kind: Gateway, name: orders-mtls}]
  roleArn: arn:aws:iam::123456789012:role/elb-envoy-proxy
  networkConfiguration:
    ipConfiguration:
      ipAddressingConfiguration: {ipv4Addressability: internal, ipv6Addressability: "off"}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata: {name: orders-blue-green, namespace: order}
spec:
  parentRefs: [{name: orders-mtls, sectionName: https}]
  hostnames: [orders.example.com]
  rules:
    - matches: [{path: {type: PathPrefix, value: /orders}}]
      backendRefs:
        - {name: api-blue, port: 8443, weight: 95}
        - {name: api-green, port: 8443, weight: 5}
---
apiVersion: gateway.networking.k8s.io/v1
kind: BackendTLSPolicy
metadata: {name: blue-server-auth, namespace: order}
spec:
  targetRefs: [{group: "", kind: Service, name: api-blue}]
  validation:
    hostname: api-blue.order.svc.cluster.local
    caCertificateRefs: [{group: "", kind: ConfigMap, name: blue-server-ca}]
---
apiVersion: gateway.networking.k8s.io/v1
kind: BackendTLSPolicy
metadata: {name: green-server-auth, namespace: order}
spec:
  targetRefs: [{group: "", kind: Service, name: api-green}]
  validation:
    hostname: api-green.order.svc.cluster.local
    caCertificateRefs: [{group: "", kind: ConfigMap, name: green-server-ca}]
