Upgrades

    Consul API Gateway v0.3.0 introduces a change for people upgrading from lower versions. Gateways with with a certificateRef defined in a different namespace now require a ReferencePolicy that explicitly allows Gateways from the gateway’s namesapce to use certificateRef in the certificateRef‘s namespace.

    Ensure that the following requirements are met prior to upgrading:

    • Consul API Gateway should be running version v0.2.1 or lower.
    • You should have the ability to run kubectl CLI commands.
    • should be configured to point to the cluster containing the installation you are upgrading.
    • You should have the following permission rights on your Kubernetes cluster:
    • (Optional) The jq command line processor for JSON can be installed, which will ease gateway retrieval during the upgrade process.

    Procedure

    1. Verify the current version of the consul-api-gateway-controller Deployment:

      1. $ kubectl get deployment --namespace consul consul-api-gateway-controller --output=jsonpath= "{@.spec.template.spec.containers[?(@.name=='api-gateway-controller')].image}"

      You should receive a response similar to the following:

      1. "hashicorp/consul-api-gateway:0.2.1"
      1. "hashicorp/consul-api-gateway:0.2.1"
    2. Retrieve all gateways that have a certificateRefs in a different namespace. If you have installed the jq utility, you can skip to . Otherwise, issue the following command to get all Gateways across all namespaces:

      1. $ kubectl get Gateway --output json --all-namespaces
      1. $ kubectl get Gateway --output json --all-namespaces

      If you have any active Gateways, you will receive output similar to the following response. The output has been truncated to show only relevant fields:

      1. apiVersion: gateway.networking.k8s.io/v1alpha2
      2. kind: Gateway
      3. metadata:
      4. name: example-gateway
      5. namespace: gateway-namespace
      6. spec:
      7. gatewayClassName: "consul-api-gateway"
      8. listeners:
      9. - name: https
      10. port: 443
      11. protocol: HTTPS
      12. allowedRoutes:
      13. namespaces:
      14. from: All
      15. tls:
      16. certificateRefs:
      17. - group: ""
      18. kind: Secret
      19. name: example-certificate
      20. namespace: certificate-namespace
      1. apiVersion: gateway.networking.k8s.io/v1alpha2
      2. kind: Gateway
      3. metadata:
      4. name: example-gateway
      5. namespace: gateway-namespace
      6. spec:
      7. gatewayClassName: "consul-api-gateway"
      8. listeners:
      9. - name: https
      10. port: 443
      11. protocol: HTTPS
      12. allowedRoutes:
      13. namespaces:
      14. from: All
      15. tls:
      16. certificateRefs:
      17. - group: ""
      18. kind: Secret
      19. name: example-certificate
      20. namespace: certificate-namespace
    3. Inspect the certificateRefs entries for each of the routes.

      If a namespace field is not defined in the certificateRefs or if the namespace matches the namespace of the parent Gateway, then no additional action is required for the certificateRefs. Otherwise, note the namespace field values for certificateRefs configurations with a namespace field that do not match the namespace of the parent Gateway. You must also note the namespace of the parent gateway. You will need these to create a ReferencePolicy that explicitly allows each cross-namespace certificateRefs-to-gateway pair. (see step 5).

      After completing this step, you will have a list of all secrets similar to the following:

      1. example-certificate:
      2. - namespace: certificate-namespace
      3. parentNamespace: gateway-namespace
      1. example-certificate:
      2. - namespace: certificate-namespace
      3. parentNamespace: gateway-namespace

      Proceed with the if your list is empty.

    4. If you have installed jq, issue the following command to get all Gateways and filter for secrets that require a ReferencePolicy.

      1. $ kubectl get Gateway -o json -A | jq -r '.items[] | {gateway_name: .metadata.name, gateway_namespace: .metadata.namespace, kind: .kind, crossNamespaceSecrets: ( .metadata.namespace as $parentnamespace | .spec.listeners[] | select(has("tls")) | .tls.certificateRefs[] | select(.namespace != null and .namespace != $parentnamespace ) )} '
      1. $ kubectl get Gateway -o json -A | jq -r '.items[] | {gateway_name: .metadata.name, gateway_namespace: .metadata.namespace, kind: .kind, crossNamespaceSecrets: ( .metadata.namespace as $parentnamespace | .spec.listeners[] | select(has("tls")) | .tls.certificateRefs[] | select(.namespace != null and .namespace != $parentnamespace ) )} '

      The output will resemble the following response if gateways that require a new ReferencePolicy are returned:

      1. {
      2. "gateway_name": "example-gateway",
      3. "gateway_namespace": "gateway-namespace",
      4. "kind": "Gateway",
      5. "crossNamespaceSecrets": {
      6. "group": "",
      7. "kind": "Secret",
      8. "name": "cexample-certificate",
      9. "namespace": "certificate-namespace"
      10. }
      11. }
      1. {
      2. "gateway_name": "example-gateway",
      3. "gateway_namespace": "gateway-namespace",
      4. "kind": "Gateway",
      5. "crossNamespaceSecrets": {
      6. "group": "",
      7. "kind": "Secret",
      8. "name": "cexample-certificate",
      9. "namespace": "certificate-namespace"
      10. }
      11. }

      If your output is empty, proceed with the .

    5. Using the list of secrets you created earlier as a guide, create a ReferencePolicy to allow each gateway cross namespace secret access. The ReferencePolicy explicitly allows each cross-namespace gateway to secret pair. The ReferencePolicy must be created in the same namespace as the certificateRefs.

      Skip to the next step if you’ve already created a ReferencePolicy.

      The following example ReferencePolicy enables example-gateway in gateway-namespace to utilize certificateRefs in the certificate-namespace namespace:

      1. apiVersion: gateway.networking.k8s.io/v1alpha2
      2. kind: ReferencePolicy
      3. metadata:
      4. name: reference-policy
      5. namespace: certificate-namespace
      6. spec:
      7. from:
      8. - group: gateway.networking.k8s.io
      9. kind: Gateway
      10. namespace: gateway-namespace
      11. to:
      12. - group: ""
      13. kind: Secret

      referencepolicy.yaml

    6. Issue the following command to apply it to your cluster:

      1. $ kubectl apply --filename referencepolicy.yaml

      Repeat this step as needed until each of your cross-namespace certificateRefs have a corresponding ReferencePolicy.

      Proceed with the .

    Consul API Gateway v0.2.0 introduces a change for people upgrading from Consul API Gateway v0.1.0. Routes with a backendRef defined in a different namespace now require a ReferencePolicy that explicitly allows traffic from the route’s namespace to the backendRef‘s namespace.

    Ensure that the following requirements are met prior to upgrading:

    • Consul API Gateway should be running version v0.1.0.
    • You should have the ability to run kubectl CLI commands.
    • should be configured to point to the cluster containing the installation you are upgrading.
    • You should have the following permission rights on your Kubernetes cluster:
    • (Optional) The command line processor for JSON can be installed, which will ease route retrieval during the upgrade process.

    Procedure

    1. Verify the current version of the consul-api-gateway-controller Deployment:

      1. $ kubectl get deployment --namespace consul consul-api-gateway-controller --output=jsonpath= "{@.spec.template.spec.containers[?(@.name=='api-gateway-controller')].image}"
      1. $ kubectl get deployment --namespace consul consul-api-gateway-controller --output=jsonpath= "{@.spec.template.spec.containers[?(@.name=='api-gateway-controller')].image}"

      You should receive the following response:

      1. "hashicorp/consul-api-gateway:0.1.0"
      1. "hashicorp/consul-api-gateway:0.1.0"
    2. Retrieve all routes that have a backend in a different namespace. If you have installed the utility, you can skip to step 4. Otherwise, issue the following command to get all HTTPRoutes and TCPRoutes across all namespaces:

      1. $ kubectl get HTTPRoute,TCPRoute --output json --all-namespaces
      1. $ kubectl get HTTPRoute,TCPRoute --output json --all-namespaces

      Note that the command only retrieves HTTPRoutes and TCPRoutes. TLSRoutes and UDPRoutes are not supported in v0.1.0.

      If you have any active HTTPRoutes or TCPRoutes, you will receive output similar to the following response. The output has been truncated to show only relevant fields:

      1. apiVersion: v1
      2. items:
      3. - apiVersion: gateway.networking.k8s.io/v1alpha2
      4. kind: HTTPRoute
      5. metadata:
      6. name: example-http-route,
      7. namespace: example-namespace,
      8. ...
      9. spec:
      10. parentRefs:
      11. - group: gateway.networking.k8s.io
      12. kind: Gateway
      13. name: gateway
      14. namespace: gw-ns
      15. rules:
      16. - backendRefs:
      17. - group: ""
      18. kind: Service
      19. name: web-backend
      20. namespace: gateway-namespace
      21. ...
      22. ...
      23. - apiVersion: gateway.networking.k8s.io/v1alpha2
      24. kind: TCPRoute
      25. metadata:
      26. name: example-tcp-route,
      27. namespace: a-different-namespace,
      28. ...
      29. spec:
      30. parentRefs:
      31. - group: gateway.networking.k8s.io
      32. kind: Gateway
      33. name: gateway
      34. namespace: gateway-namespace
      35. rules:
      36. - backendRefs:
      37. - group: ""
      38. kind: Service
      39. name: web-backend
      40. namespace: gateway-namespace
      41. ...
      42. ...
      1. apiVersion: v1
      2. items:
      3. - apiVersion: gateway.networking.k8s.io/v1alpha2
      4. kind: HTTPRoute
      5. metadata:
      6. name: example-http-route,
      7. namespace: example-namespace,
      8. ...
      9. spec:
      10. parentRefs:
      11. - group: gateway.networking.k8s.io
      12. kind: Gateway
      13. name: gateway
      14. namespace: gw-ns
      15. rules:
      16. - backendRefs:
      17. - group: ""
      18. kind: Service
      19. name: web-backend
      20. namespace: gateway-namespace
      21. ...
      22. ...
      23. - apiVersion: gateway.networking.k8s.io/v1alpha2
      24. kind: TCPRoute
      25. metadata:
      26. name: example-tcp-route,
      27. namespace: a-different-namespace,
      28. ...
      29. spec:
      30. parentRefs:
      31. - group: gateway.networking.k8s.io
      32. kind: Gateway
      33. name: gateway
      34. namespace: gateway-namespace
      35. rules:
      36. - backendRefs:
      37. - group: ""
      38. kind: Service
      39. name: web-backend
      40. namespace: gateway-namespace
      41. ...
      42. ...
    3. Inspect the backendRefs entries for each of the routes.

      If a namespace field is not defined in the backendRef or if the namespace matches the namespace of the route, then no additional action is required for the backendRef. Otherwise, note the group, kind, name, and namespace field values for backendRef configurations that have a namespace defined that do not match the namespace of the parent route. You must also note the kind and namespace of the parent route. You will need these to create a ReferencePolicy that explicitly allows each cross-namespace route-to-service pair (see ).

      After completing this step, you will have a list of all routes similar to the following:

      1. example-http-route:
      2. - namespace: example-namespace
      3. kind: HTTPRoute
      4. backendReferences:
      5. - group : ""
      6. kind: Service
      7. name: web-backend
      8. example-tcp-route:
      9. - namespace: a-different-namespace
      10. backendReferences:
      11. - group : ""
      12. kind: Service
      13. name: web-backend
      14. namespace: gateway-namespace
      1. example-http-route:
      2. - namespace: example-namespace
      3. kind: HTTPRoute
      4. backendReferences:
      5. - group : ""
      6. kind: Service
      7. name: web-backend
      8. namespace: gateway-namespace
      9. example-tcp-route:
      10. - namespace: a-different-namespace
      11. kind: HTTPRoute
      12. backendReferences:
      13. - group : ""
      14. kind: Service
      15. name: web-backend
      16. namespace: gateway-namespace

      Proceed with standard-upgrade if your list is empty.

    4. If you have installed , issue the following command to get all HTTPRoutes and TCPRoutes and filter for routes that require a ReferencePolicy.

      1. $ kubectl get HTTPRoute,TCPRoute -o json -A | jq -r '.items[] | {name: .metadata.name, namespace: .metadata.namespace, kind: .kind, crossNamespaceBackendReferences: ( .metadata.namespace as $parentnamespace | .spec.rules[] .backendRefs[] | select(.namespace != null and .namespace != $parentnamespace ) )} '
      1. $ kubectl get HTTPRoute,TCPRoute -o json -A | jq -r '.items[] | {name: .metadata.name, namespace: .metadata.namespace, kind: .kind, crossNamespaceBackendReferences: ( .metadata.namespace as $parentnamespace | .spec.rules[] .backendRefs[] | select(.namespace != null and .namespace != $parentnamespace ) )} '

      Note that the command retrieves all HTTPRoutes and TCPRoutes. TLSRoutes and UDPRoutes are not supported in v0.1.0.

      The output will resemble the following response if routes that require a new ReferencePolicy are returned:

      1. {
      2. "name": "example-http-route",
      3. "namespace": "example-namespace",
      4. "kind": "HTTPRoute",
      5. "crossNamespaceBackendReferences": {
      6. "group": "",
      7. "kind": "Service",
      8. "name": "web-backend",
      9. "namespace": "gateway-namespace",
      10. "port": 8080,
      11. "weight": 1
      12. }
      13. }
      14. {
      15. "name": "example-tcp-route",
      16. "namespace": "a-different-namespace",
      17. "kind": "TCPRoute",
      18. "crossNamespaceBackendReferences": {
      19. "group": "",
      20. "kind": "Service",
      21. "name": "web-backend",
      22. "namespace": "gateway-namespace",
      23. "port": 8080,
      24. "weight": 1
      25. }
      26. }

      If your output is empty, proceed with the standard-upgrade.

    5. Skip to the next step if you’ve already created a ReferencePolicy.

      The following example ReferencePolicy enables HTTPRoute traffic from the example-namespace to Kubernetes Services in the web-backend namespace:

      1. apiVersion: gateway.networking.k8s.io/v1alpha2
      2. kind: ReferencePolicy
      3. metadata:
      4. name: reference-policy
      5. namespace: gateway-namespace
      6. spec:
      7. from:
      8. - group: gateway.networking.k8s.io
      9. kind: HTTPRoute
      10. namespace: example-namespace
      11. to:
      12. - group: ""
      13. kind: Service
      14. name: web-backend

      Upgrades - 图2

      referencepolicy.yaml

      1. apiVersion: gateway.networking.k8s.io/v1alpha2
      2. kind: ReferencePolicy
      3. metadata:
      4. name: reference-policy
      5. namespace: gateway-namespace
      6. spec:
      7. from:
      8. - group: gateway.networking.k8s.io
      9. kind: HTTPRoute
      10. namespace: example-namespace
      11. to:
      12. - group: ""
      13. kind: Service
      14. name: web-backend
    6. If you have already created a ReferencePolicy, modify it to allow your route and save it as referencepolicy.yaml. Note that each ReferencePolicy only supports one to field and one from field (refer the documentation). As a result, you may need to create multiple ReferencePolicys.

    7. Issue the following command to apply it to your cluster:

      1. $ kubectl apply --filename referencepolicy.yaml
      1. $ kubectl apply --filename referencepolicy.yaml

      Repeat this step as needed until each of your cross-namespace routes have a corresponding ReferencePolicy.

      Proceed with the standard-upgrade.

    Note: When you see VERSION in examples of commands or configuration settings, replace VERSION with the version number of the release you are installing, like 0.2.0. If there is a lower case “v” in front of VERSION the version number needs to follow the “v” as is v0.2.0

    Ensure that the following requirements are met prior to upgrading:

    • You should have the ability to run kubectl CLI commands.
    • should be configured to point to the cluster containing the installation you are upgrading.

    Procedure

    This is the upgrade path to use when there are no version specific steps to take.

    1. Issue the following command to install the new version of CRDs into your cluster:

      1. $ kubectl apply --kustomize="github.com/hashicorp/consul-api-gateway/config/crd?ref=vVERSION"
      1. $ kubectl apply --kustomize="github.com/hashicorp/consul-api-gateway/config/crd?ref=vVERSION"
    2. Update apiGateway.image in values.yaml:

      1. ...
      2. apiGateway:
      3. image: hashicorp/consul-api-gateway:VERSION
      4. ...

      values.yaml

      1. ...
      2. apiGateway:
      3. image: hashicorp/consul-api-gateway:VERSION
      4. ...
    3. Issue the following command to upgrade your Consul installation:

      1. $ helm upgrade --values values.yaml --namespace consul --version <NEW_VERSION> <DEPLOYMENT_NAME> hashicorp/consul
      1. $ helm upgrade --values values.yaml --namespace consul --version <NEW_VERSION> <DEPLOYMENT_NAME> hashicorp/consul

      Note that the upgrade will cause the Consul API Gateway controller shut down and restart with the new version.

    4. According to the Kubernetes Gateway API specification, configurations should only be applied to a gateway upon creation. To see the effects on preexisting gateways after upgrading your CRD installation, delete and recreate any gateways by issuing the following commands:

      1. $ kubectl delete --filename <path_to_gateway_config.yaml>
      2. $ kubectl create --filename <path_to_gateway_config.yaml>
      1. $ kubectl delete --filename <path_to_gateway_config.yaml>
      2. $ kubectl create --filename <path_to_gateway_config.yaml>
      1. $ kubectl create --filename <path_to_route_config.yaml>

    No additional configuration changes are required for this upgrade.