apisix

by joaquinito2051

Helm chartv3.1.0App 3.21.0

A Helm chart for Apache APISIX v3

About this chart

Apache APISIX for Kubernetes

Apache APISIX is a dynamic, real-time, high-performance API gateway.

APISIX provides rich traffic management features such as load balancing, dynamic upstream, canary release, circuit breaking, authentication, observability, and more.

You can use Apache APISIX to handle traditional north-south traffic, as well as east-west traffic between services. It can also be used as a k8s ingress controller.

This chart bootstraps all the components needed to run Apache APISIX on a Kubernetes Cluster using Helm.

Prerequisites

  • Kubernetes v1.14+
  • Helm v3.8+

Install

To install the chart with the release name my-apisix:

helm repo add apisix https://apache.github.io/apisix-helm-chart
helm repo update

helm install [RELEASE_NAME] apisix/apisix --namespace ingress-apisix --create-namespace

Uninstall

To uninstall/delete a Helm release my-apisix:

helm delete [RELEASE_NAME] --namespace ingress-apisix

The command removes all the Kubernetes components associated with the chart and deletes the release.

Admin API keys

The chart does not ship a default Admin API key. When the release has an Admin API (the traditional and control_plane roles, without apisix.fullCustomConfig) and you don't set the keys yourself, the chart generates random keys for the admin and viewer roles when the release is installed and stores them in the Secret <fullname>-admin-credentials (apisix-admin-credentials for the release name apisix). helm upgrade keeps them, and the bundled ingress controller reads the admin key from the same Secret.

To print the admin key:

kubectl get secret --namespace <namespace> apisix-admin-credentials -o jsonpath='{.data.admin}' | base64 -d

To use your own keys, either set apisix.admin.credentials.admin and apisix.admin.credentials.viewer, or store them in a Secret and set apisix.admin.credentials.secretName (plus secretAdminKey / secretViewerKey if the Secret uses other field names). The publicly known keys that chart versions before 3.0.0 used as defaults are rejected wherever the chart sees them: in apisix.admin.credentials, in apisix.fullCustomConfig.config, in the generated Secret, and in the Secret named by secretName when the chart can read it.

On upgrade, a generated key that is missing from the Secret fails the release instead of being replaced (see Upgrading). The only exception is apisix.admin.enabled: false: no client can use the keys then, so missing ones are generated again. helm uninstall deletes the generated Secret, so a new install gets new keys.

To let the chart manage keys that an existing release already uses (for example after taking them out of apisix.admin.credentials), create the Secret first and let Helm adopt it, then upgrade:

kubectl -n <namespace> create secret generic <fullname>-admin-credentials \
  --from-literal=admin=<admin key> --from-literal=viewer=<viewer key>
kubectl -n <namespace> label secret <fullname>-admin-credentials app.kubernetes.io/managed-by=Helm
kubectl -n <namespace> annotate secret <fullname>-admin-credentials \
  meta.helm.sh/release-name=<release> meta.helm.sh/release-namespace=<namespace>

Keys from a Secret reach APISIX as environment variables. Don't use a key made only of digits, or true / false: APISIX converts such values to a number or a boolean, and the key stops matching (apache/apisix#14178).

GitOps and offline rendering

The chart keeps a generated key by reading the Secret with Helm's lookup function. lookup returns nothing when the chart is rendered without access to the cluster: helm template, helm install --dry-run (client side), and Argo CD, which renders every application with helm template. In those cases a new key is generated on every render. Under Argo CD, every sync then writes a new key into the Secret while the running APISIX pods keep the old one, and the bundled ingress controller, which follows the Secret, gets 401 Unauthorized from the Admin API.

With such tools, create the Secret yourself (for example with External Secrets or Sealed Secrets) and set apisix.admin.credentials.secretName. With Argo CD you can instead keep the first generated key by adding this to the Application:

spec:
  ignoreDifferences:
    - kind: Secret
      name: <fullname>-admin-credentials
      jsonPointers:
        - /data
  syncPolicy:
    syncOptions:
      - RespectIgnoreDifferences=true

Flux runs helm install and helm upgrade, so generated keys are kept as with the Helm CLI.

Previews that cannot read the cluster (helm upgrade --dry-run=client, helm diff upgrade on Helm 3, helmfile diff) show a newly generated key for the Secret, but the actual upgrade keeps the stored one. Such previews also cannot show an ADMIN KEY ERROR that the real upgrade would raise. To preview against the cluster, use helm upgrade --dry-run=server --hide-secret (Helm 3.15 or later; without --hide-secret the output contains the keys); with helmfile, pass --template-args="--dry-run=server".

Rotating keys

Keys set in apisix.admin.credentials are part of the APISIX ConfigMap, so helm upgrade restarts APISIX with the new keys. Keys from a Secret, including the generated Secret, are read when APISIX starts: after changing the Secret, run kubectl rollout restart on the APISIX workload. The bundled ingress controller watches the Secret and picks up the new admin key by itself. To rotate a generated key, change it in the Secret; later upgrades keep the new value.

helm rollback, including the automatic rollback of --atomic (Helm 3) or --rollback-on-failure (Helm 4), re-applies the Secret stored in the target revision, so rolling back to a revision rendered before a rotation restores the old key. After rotating, run helm upgrade once so the release records the new key, and don't roll back past that revision. To keep keys out of the release history, use apisix.admin.credentials.secretName.

Upgrading

To 3.1.0

This chart upgrades the default gateway to Apache APISIX 3.21.0.

  • If you set apisix.fullCustomConfig.enabled: true for a traditional or control_plane deployment with deployment.admin.admin_key_required enabled, give every entry in deployment.admin.admin_key an explicit role of admin or viewer. Quote numeric-looking key values in YAML, for example key: "1234567890123456". These checks also apply to traditional deployments with the Admin API disabled.
  • If you use configuration encryption, back up etcd before upgrading. Pause Admin API writes while old and new gateway versions run together. APISIX 3.21.0 prefixes newly encrypted plugin configuration and metadata values with $ENC$v1$. If you have re-saved encrypted resources and need to roll back to a gateway build that cannot read this prefix, restore the pre-upgrade etcd data before starting that build.

See the APISIX 3.21.0 release notes for the full upstream upgrade guidance.

To 3.0.0

Chart 3.0.0 no longer uses the publicly known default Admin API keys (edd1c9f034335f136f87ad84b625c8f1 and 4054f7cf07e344346cd3f287985e76a2).

  • If you already set apisix.admin.credentials.admin and viewer, or secretName, to other keys, nothing changes, with one exception: inline keys are now used exactly as given. Earlier versions rendered them unquoted, so YAML dropped leading and trailing spaces, tabs and line breaks (for example the newline at the end of a file passed with --set-file), the quotes around a key that starts with one, and a # with everything after it. Such keys now fail with ADMIN KEY ERROR instead of silently becoming a key that clients don't send; remove those parts.
  • If your release used the defaults, helm upgrade fails with ADMIN KEY ERROR before changing anything. Choose new keys, pass them with --set apisix.admin.credentials.admin=<key> --set apisix.admin.credentials.viewer=<key> or apisix.admin.credentials.secretName, upgrade again, and give the new admin key to your Admin API clients.
  • Argo CD and other tools that render the chart with helm template cannot run this check: the first sync of 3.0.0 replaces the public keys with random ones, cutting off Admin API clients, and later renders replace them again (see GitOps and offline rendering). Create a Secret with your keys and set apisix.admin.credentials.secretName in the same change that moves the application to 3.0.0.
  • With the bundled ingress controller, remove ingress-controller.gatewayProxy.createDefault and any admin key set under ingress-controller.gatewayProxy: the apisix chart now creates the GatewayProxy with this release's Admin API Service and admin key. If you keep createDefault: true, set its admin key yourself. When it uses this release's Admin API Service (<fullname>-admin), directly or through endpoints that name it, it must be the key APISIX uses (the same value, or a secretKeyRef to the same Secret and field), or the chart refuses to render. Without endpoints or ingress-controller.gatewayProxy.provider.controlPlane.service.name, the controller chart uses ingress-controller.apisix.adminService.name, which defaults to apisix-admin. If that default is not this release's Service and this release has its own Admin API, the chart refuses to render and asks you to set the Service name. A data-plane release can keep pointing its controller at a control plane's Admin API Service this way.
  • With apisix.admin.credentials.secretName, the chart reads that Secret with lookup to reject the public default keys, so the identity that runs Helm needs get on Secrets in the release namespace. Helm's default storage driver keeps releases in Secrets and already needs it.
  • If the release has no Admin API (the data_plane role, apisix.fullCustomConfig, or apisix.admin.enabled: false) and the bundled ingress controller is enabled, the chart cannot create the GatewayProxy and refuses to render. Point the controller at your control plane with ingress-controller.gatewayProxy.createDefault: true and its endpoints and admin key, or set ingress-controller.gatewayProxy.name: "" to leave the IngressClass without a GatewayProxy.
  • The bundled apisix-ingress-controller chart moves from 1.3.0 to 1.5.0. Its Gateway API CRDs are no longer installed from crds/: they are rendered as templates (ingress-controller.crds.gatewayAPI.enabled), only when they are missing or belong to this release, and kept on uninstall.
  • The bundled etcd accepts client connections only from its own pods and the APISIX pods of this release (etcd.networkPolicy.allowExternal: false). During the upgrade, APISIX pods of the previous version cannot reach etcd until they are replaced: Admin API requests that reach them fail, and they receive no configuration changes, but they keep serving the routes they have. With one replica this lasts a few seconds; with several replicas or a DaemonSet, it lasts until the rollout has replaced every old pod. If other pods connect to etcd, for example a data plane installed as another release, the apisix-dashboard chart, APISIX pods with hostNetwork: true, or a pod that runs etcdctl, allow them as described in Access to the bundled etcd. A DaemonSet with updateStrategy.type: OnDelete keeps its old pods, which cannot reach etcd, until you delete them.
  • Don't upgrade with --reuse-values, or with spec.upgrade.preserveValues: true in Flux: they render with the default values of the chart version you upgrade from, in which etcd accepts every pod, so the chart refuses to render (from 2.0 to 2.7, the etcd chart's image check fails first). Use --reset-then-reuse-values (Helm 3.14 or later), or pass your values again; helm get values <release> --namespace <namespace> -o yaml prints the ones you set. Don't add --all: its output also holds the defaults of the old version, among them etcd.networkPolicy.allowExternal: true, which keeps etcd open to every pod without an error. In Flux, set spec.upgrade.preserveValues: false.
  • The chart now refuses to render etcd.metrics.enabled with the metrics on the client port, a release name, etcd.nameOverride or etcd.fullnameOverride that makes the etcd client label longer than 63 characters, and hostNetwork: true without an etcd.networkPolicy.extraIngress rule that can admit the addresses of the nodes, unless etcd.networkPolicy.allowExternal is true. See Access to the bundled etcd.
  • With etcd.auth.rbac.existingSecret, APISIX now reads the root password from that Secret, as etcd does. Earlier versions read it from the Secret <etcd fullname>, which the etcd chart does not create in that case.

Access to the bundled etcd

APISIX keeps its configuration in etcd, including routes, consumers and their credentials. Unless etcd requires authentication, which it does not by default, a client that can connect to etcd can read and change all of it without an Admin API key. The bundled etcd therefore accepts client connections only from its own pods and from pods labelled <etcd fullname>-client: "true", which the chart adds to the APISIX pods and to the pre-upgrade, snapshot and defragmentation jobs of the etcd chart. For a release named apisix, the label is apisix-etcd-client: "true". This needs a network plugin that enforces NetworkPolicies.

To let another pod in the release's namespace connect, add the label to it before you upgrade this release, for example with podLabels for a data plane installed as another release. Set the label

Deploy apisix with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has apisix on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartapisix is pinned at v3.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply