From 516fade09c7e59d441beb4bc6d49c43fba888c14 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Fri, 24 Nov 2023 09:40:03 +0530 Subject: [PATCH 1/3] add standalone support with helm chart Signed-off-by: Ashish Tiwari --- charts/apisix/README.md | 2 +- charts/apisix/templates/apisix-config-cm.yml | 32 +++ charts/apisix/templates/configmap.yaml | 5 +- charts/apisix/templates/deployment.yaml | 12 + charts/apisix/values.yaml | 2 +- docs/en/latest/FAQ.md | 255 +------------------ 6 files changed, 50 insertions(+), 258 deletions(-) create mode 100644 charts/apisix/templates/apisix-config-cm.yml diff --git a/charts/apisix/README.md b/charts/apisix/README.md index 4ba433f6..36482ae7 100644 --- a/charts/apisix/README.md +++ b/charts/apisix/README.md @@ -63,7 +63,7 @@ The command removes all the Kubernetes components associated with the chart and | apisix.customPlugins.plugins[0].configMap | object | `{"mounts":[{"key":"the-file-name","path":"mount-path"}],"name":"configmap-name"}` | plugin codes can be saved inside configmap object. | | apisix.customPlugins.plugins[0].configMap.mounts | list | `[{"key":"the-file-name","path":"mount-path"}]` | since keys in configmap is flat, mountPath allows to define the mount path, so that plugin codes can be mounted hierarchically. | | apisix.customPlugins.plugins[0].configMap.name | string | `"configmap-name"` | name of configmap. | -| apisix.deployment.mode | string | `"traditional"` | Apache APISIX deployment mode Optional: traditional, decoupled ref: https://apisix.apache.org/docs/apisix/deployment-modes/ | +| apisix.deployment.mode | string | `"traditional"` | Apache APISIX deployment mode Optional: traditional, decoupled, standalone ref: https://apisix.apache.org/docs/apisix/deployment-modes/ | | apisix.deployment.role | string | `"traditional"` | Deployment role Optional: traditional, data_plane, control_plane ref: https://apisix.apache.org/docs/apisix/deployment-modes/ | | apisix.discovery.enabled | bool | `false` | Enable or disable Apache APISIX integration service discovery | | apisix.discovery.registry | object | `{}` | Registry is the same to the one in APISIX [config-default.yaml](https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L281), and refer to such file for more setting details. also refer to [this documentation for integration service discovery](https://apisix.apache.org/docs/apisix/discovery) | diff --git a/charts/apisix/templates/apisix-config-cm.yml b/charts/apisix/templates/apisix-config-cm.yml new file mode 100644 index 00000000..bcd297ac --- /dev/null +++ b/charts/apisix/templates/apisix-config-cm.yml @@ -0,0 +1,32 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{{- if eq .Values.deployment.mode "standalone" }} +kind: ConfigMap +apiVersion: v1 +metadata: + name: apisix.yaml +data: + apisix.yaml: | + routes: + - + uri: /hi + upstream: + nodes: + "127.0.0.1:1980": 1 + type: roundrobin + #END +{{- end }} \ No newline at end of file diff --git a/charts/apisix/templates/configmap.yaml b/charts/apisix/templates/configmap.yaml index b7317e64..bbb2a3a6 100644 --- a/charts/apisix/templates/configmap.yaml +++ b/charts/apisix/templates/configmap.yaml @@ -295,7 +295,7 @@ data: {{- if eq .Values.apisix.deployment.role "data_plane" }} role_data_plane: - config_provider: etcd + config_provider: {{- eq .Values.deployment.mode "standalone" | ternary "yaml" "etcd" | indent 1 }} {{- end }} {{- if not (eq .Values.apisix.deployment.role "data_plane") }} @@ -339,7 +339,7 @@ data: {{- end }} role: viewer {{- end }} - + {{- if not (eq .Values.deployment.mode "standalone")}} etcd: {{- if .Values.etcd.enabled }} host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. @@ -371,4 +371,5 @@ data: sni: "{{ .Values.etcd.auth.tls.sni }}" {{- end }} {{- end }} + {{- end }} diff --git a/charts/apisix/templates/deployment.yaml b/charts/apisix/templates/deployment.yaml index 5a9aa5d8..65c2579a 100644 --- a/charts/apisix/templates/deployment.yaml +++ b/charts/apisix/templates/deployment.yaml @@ -67,6 +67,9 @@ spec: {{- . | toYaml | nindent 12 }} {{- end }} image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}" + {{- if eq .Values.deployment.mode "standalone" }} + command: ["sh", "-c","ln -s /apisix-config/apisix.yaml /usr/local/apisix/conf/apisix.yaml && /docker-entrypoint.sh docker-start"] + {{- end }} imagePullPolicy: {{ .Values.image.pullPolicy }} env: {{- if .Values.timezone }} @@ -166,6 +169,10 @@ spec: - -c - "sleep 30" volumeMounts: + {{- if eq .Values.deployment.mode "standalone" }} + - mountPath: /apisix-config + name: apisix-admin + {{- end }} {{- if .Values.apisix.setIDFromPodUID }} - mountPath: /usr/local/apisix/conf/apisix.uid name: id @@ -229,6 +236,11 @@ spec: {{- toYaml .Values.extraInitContainers | nindent 8 }} {{- end }} volumes: + {{- if eq .Values.deployment.mode "standalone" }} + - configMap: + name: apisix.yaml + name: apisix-admin + {{- end }} - configMap: name: {{ include "apisix.fullname" . }} name: apisix-config diff --git a/charts/apisix/values.yaml b/charts/apisix/values.yaml index d84e7541..4debf80f 100644 --- a/charts/apisix/values.yaml +++ b/charts/apisix/values.yaml @@ -294,7 +294,7 @@ apisix: deployment: # -- Apache APISIX deployment mode - # Optional: traditional, decoupled + # Optional: traditional, decoupled, standalone # # ref: https://apisix.apache.org/docs/apisix/deployment-modes/ mode: traditional diff --git a/docs/en/latest/FAQ.md b/docs/en/latest/FAQ.md index 2c5c5e62..a5d85c24 100644 --- a/docs/en/latest/FAQ.md +++ b/docs/en/latest/FAQ.md @@ -39,260 +39,7 @@ helm install apisix apisix/apisix \ ### How to install Apache APISIX running in standalone mode? -Helm chart does not provide a direct way to deploy Apache APISIX running in standalone mode. You can install it in the following manner. - -Create a `deploy.yaml` with the following content. - - - - - -```yaml -# deploy.yaml -kind: ConfigMap -apiVersion: v1 -metadata: - name: apisix-gw-config.yaml -data: - config.yaml: | - deployment: - role: data_plane - role_data_plane: - config_provider: yaml ---- -kind: ConfigMap -apiVersion: v1 -metadata: - name: apisix.yaml -data: - apisix.yaml: | - routes: - - - uri: /hi - upstream: - nodes: - "127.0.0.1:1980": 1 - type: roundrobin - #END ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: apisix-deployment -spec: - replicas: 1 - selector: - matchLabels: - app: apisix-deployment - strategy: - rollingUpdate: - maxSurge: 50% - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: apisix-deployment - spec: - terminationGracePeriodSeconds: 0 - containers: - - livenessProbe: - failureThreshold: 3 - initialDelaySeconds: 1 - periodSeconds: 2 - successThreshold: 1 - tcpSocket: - port: 9080 - timeoutSeconds: 2 - readinessProbe: - failureThreshold: 3 - initialDelaySeconds: 1 - periodSeconds: 2 - successThreshold: 1 - tcpSocket: - port: 9080 - timeoutSeconds: 2 - image: "apache/apisix:2.99.0-centos" - imagePullPolicy: IfNotPresent - name: apisix-deployment - # Create a soft link to link the apisix.yaml file in the mount directory to /usr/local/apisix/conf/apisix.yaml. - command: ["sh", "-c","ln -s /apisix-config/apisix.yaml /usr/local/apisix/conf/apisix.yaml && /docker-entrypoint.sh docker-start"] - ports: - - containerPort: 9080 - name: "http" - protocol: "TCP" - - containerPort: 9443 - name: "https" - protocol: "TCP" - - volumeMounts: - - mountPath: /usr/local/apisix/conf/config.yaml - name: apisix-config-yaml-configmap - subPath: config.yaml - # configMap directory mounts - - mountPath: /apisix-config - name: apisix-admin - volumes: - - configMap: - name: apisix-gw-config.yaml - name: apisix-config-yaml-configmap - - configMap: - name: apisix.yaml - name: apisix-admin ---- -apiVersion: v1 -kind: Service -metadata: - name: apisix-service -spec: - selector: - app: apisix-deployment - ports: - - name: http - port: 9080 - protocol: TCP - targetPort: 9080 - - name: https - port: 9443 - protocol: TCP - targetPort: 9443 - type: NodePort -``` - - - - - -```yaml -# deploy.yaml -kind: ConfigMap -apiVersion: v1 -metadata: - name: apisix-gw-config.yaml -data: - config.yaml: | - apisix: - enable_admin: false - config_center: yaml ---- -kind: ConfigMap -apiVersion: v1 -metadata: - name: apisix.yaml -data: - apisix.yaml: | - routes: - - - uri: /hi - upstream: - nodes: - "127.0.0.1:1980": 1 - type: roundrobin - #END ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: apisix-deployment -spec: - replicas: 1 - selector: - matchLabels: - app: apisix-deployment - strategy: - rollingUpdate: - maxSurge: 50% - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: apisix-deployment - spec: - terminationGracePeriodSeconds: 0 - containers: - - livenessProbe: - failureThreshold: 3 - initialDelaySeconds: 1 - periodSeconds: 2 - successThreshold: 1 - tcpSocket: - port: 9080 - timeoutSeconds: 2 - readinessProbe: - failureThreshold: 3 - initialDelaySeconds: 1 - periodSeconds: 2 - successThreshold: 1 - tcpSocket: - port: 9080 - timeoutSeconds: 2 - image: "apache/apisix:2.15.0-alpine" - imagePullPolicy: IfNotPresent - name: apisix-deployment - # Create a soft link to link the apisix.yaml file in the mount directory to /usr/local/apisix/conf/apisix.yaml. - command: ["sh", "-c", "ln -s /apisix-config/apisix.yaml /usr/local/apisix/conf/apisix.yaml && /usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"] - ports: - - containerPort: 9080 - name: "http" - protocol: "TCP" - - containerPort: 9443 - name: "https" - protocol: "TCP" - volumeMounts: - - mountPath: /usr/local/apisix/conf/config.yaml - name: apisix-config-yaml-configmap - subPath: config.yaml - # configMap directory mounts - - mountPath: /apisix-config - name: apisix-admin - volumes: - - configMap: - name: apisix-gw-config.yaml - name: apisix-config-yaml-configmap - - configMap: - name: apisix.yaml - name: apisix-admin ---- -apiVersion: v1 -kind: Service -metadata: - name: apisix-service -spec: - selector: - app: apisix-deployment - ports: - - name: http - port: 9080 - protocol: TCP - targetPort: 9080 - - name: https - port: 9443 - protocol: TCP - targetPort: 9443 - type: NodePort -``` - - - - - -Apply the configuration in `deploy.yaml` to pod. - -```shell -kubectl apply -f deploy.yaml -``` - -:::note -1. The mount of the `apisix.yaml` file requires the injection of the softlink command, so do not change the configMap mount directory to `/usr/local/apisix/conf`, to avoid other configuration files being overwritten. -2. The `apisix.yaml` is mounted as a configMap, so there will be a delay in reloading the rules after `apisix.yaml` is changed; please refer to this [document](https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically) for details. -::: +helm install apisix apisix/apisix --set deployment.mode=standalone --set etcd.enabled=false --set deployment.role=data_plane ### Why get 403 when I access Apache APISIX admin api? From ab7376ddb9712829992e6fa91ee465f0e9b39eb9 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Fri, 24 Nov 2023 10:10:16 +0530 Subject: [PATCH 2/3] fix syntax err Signed-off-by: Ashish Tiwari --- charts/apisix/templates/apisix-config-cm.yml | 2 +- charts/apisix/templates/configmap.yaml | 4 ++-- charts/apisix/templates/deployment.yaml | 6 +++--- docs/en/latest/FAQ.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/charts/apisix/templates/apisix-config-cm.yml b/charts/apisix/templates/apisix-config-cm.yml index bcd297ac..10151966 100644 --- a/charts/apisix/templates/apisix-config-cm.yml +++ b/charts/apisix/templates/apisix-config-cm.yml @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -{{- if eq .Values.deployment.mode "standalone" }} +{{- if eq .Values.apisix.deployment.mode "standalone" }} kind: ConfigMap apiVersion: v1 metadata: diff --git a/charts/apisix/templates/configmap.yaml b/charts/apisix/templates/configmap.yaml index bbb2a3a6..e3917c6b 100644 --- a/charts/apisix/templates/configmap.yaml +++ b/charts/apisix/templates/configmap.yaml @@ -295,7 +295,7 @@ data: {{- if eq .Values.apisix.deployment.role "data_plane" }} role_data_plane: - config_provider: {{- eq .Values.deployment.mode "standalone" | ternary "yaml" "etcd" | indent 1 }} + config_provider: {{- eq .Values.apisix.deployment.mode "standalone" | ternary "yaml" "etcd" | indent 1 }} {{- end }} {{- if not (eq .Values.apisix.deployment.role "data_plane") }} @@ -339,7 +339,7 @@ data: {{- end }} role: viewer {{- end }} - {{- if not (eq .Values.deployment.mode "standalone")}} + {{- if not (eq .Values.apisix.deployment.mode "standalone")}} etcd: {{- if .Values.etcd.enabled }} host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. diff --git a/charts/apisix/templates/deployment.yaml b/charts/apisix/templates/deployment.yaml index 65c2579a..2a92928c 100644 --- a/charts/apisix/templates/deployment.yaml +++ b/charts/apisix/templates/deployment.yaml @@ -67,7 +67,7 @@ spec: {{- . | toYaml | nindent 12 }} {{- end }} image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}" - {{- if eq .Values.deployment.mode "standalone" }} + {{- if eq .Values.apisix.deployment.mode "standalone" }} command: ["sh", "-c","ln -s /apisix-config/apisix.yaml /usr/local/apisix/conf/apisix.yaml && /docker-entrypoint.sh docker-start"] {{- end }} imagePullPolicy: {{ .Values.image.pullPolicy }} @@ -169,7 +169,7 @@ spec: - -c - "sleep 30" volumeMounts: - {{- if eq .Values.deployment.mode "standalone" }} + {{- if eq .Values.apisix.deployment.mode "standalone" }} - mountPath: /apisix-config name: apisix-admin {{- end }} @@ -236,7 +236,7 @@ spec: {{- toYaml .Values.extraInitContainers | nindent 8 }} {{- end }} volumes: - {{- if eq .Values.deployment.mode "standalone" }} + {{- if eq .Values.apisix.deployment.mode "standalone" }} - configMap: name: apisix.yaml name: apisix-admin diff --git a/docs/en/latest/FAQ.md b/docs/en/latest/FAQ.md index a5d85c24..3e807016 100644 --- a/docs/en/latest/FAQ.md +++ b/docs/en/latest/FAQ.md @@ -39,7 +39,7 @@ helm install apisix apisix/apisix \ ### How to install Apache APISIX running in standalone mode? -helm install apisix apisix/apisix --set deployment.mode=standalone --set etcd.enabled=false --set deployment.role=data_plane +helm install apisix apisix/apisix --set apisix.deployment.mode=standalone --set etcd.enabled=false --set apisix.deployment.role=data_plane ### Why get 403 when I access Apache APISIX admin api? From c56b3160df122eadf395429b93d1635f0abfad94 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 24 Nov 2023 14:57:36 +0545 Subject: [PATCH 3/3] Update charts/apisix/templates/apisix-config-cm.yml --- charts/apisix/templates/apisix-config-cm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/apisix/templates/apisix-config-cm.yml b/charts/apisix/templates/apisix-config-cm.yml index 10151966..d76fe992 100644 --- a/charts/apisix/templates/apisix-config-cm.yml +++ b/charts/apisix/templates/apisix-config-cm.yml @@ -29,4 +29,4 @@ data: "127.0.0.1:1980": 1 type: roundrobin #END -{{- end }} \ No newline at end of file +{{- end }}