Tips: The Kubernetes cluster deployment method is recommended for production and test environments.
Install Apache APISIX in Kubernetes
kube config
file locally to facilitate local debuggingStart minikube.
Location: ~/.kube/config
Copy the config file to your local development environment, the path should be configured in apisix-ingress-controller by specifying --kuebconfig
option.
Your APISIX service address should be configured in apisix-ingress-controller by specifying --apisix-base-url
option.
$ make build $ ./apisix-ingress-controller ingress \ --kubeconfig /path/to/kubeconfig \ --http-listen :8080 \ --log-output stderr \ --apisix-base-url http://apisix-service:port/apisix
Tips: The program may print some error logs, indicating that the resource cannot be found. Continue with the following steps to define the route through CRDs.
Take the back-end service httpserver
as an example (you can choose any upstream service for test).
In fact, in order to reduce the trouble caused by ingress migration, we try to keep the structure of ApisixRoute consistent with the original ingress.
The configuration differences with nginx-ingress are
apiVersion
and kind
are different./hello*
.kubectl apply -f - <<EOF apiVersion: apisix.apache.org/v1 kind: ApisixRoute metadata: name: httpserver-route spec: rules: - host: test.apisix.apache.org http: paths: - backend: serviceName: httpserver servicePort: 8080 path: /hello* EOF
In addition, ApisixRoute
also continues to support the definition with annotation, you can also define as below.
apiVersion: apisix.apache.org/v1 kind: ApisixRoute metadata: annotations: k8s.apisix.apache.org/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,openID,audiotoken k8s.apisix.apache.org/cors-allow-methods: HEAD,GET,POST,PUT,PATCH,DELETE k8s.apisix.apache.org/cors-allow-origin: '*' k8s.apisix.apache.org/enable-cors: "true" k8s.apisix.apache.org/ssl-redirect: "false" k8s.apisix.apache.org/whitelist-source-range: 1.2.3.4,2.2.0.0/16 name: httpserver-route spec: rules: - host: test1.apisix.apache.org http: paths: - backend: serviceName: httpserver servicePort: 8080 path: /hello* plugins: - enable: true name: proxy-rewrite config: regex_uri: - '^/(.*)' - '/voice-copy-outer-service/$1' scheme: http host: internalalpha.talkinggenie.com enable_websocket: true
The definition in config needs to follow the schema definition of the plugin proxy-rewrite.
If the plug-in schema is an array, you need to change the config
field to config_set
.
kubectl apply -f - <<EOF apiVersion: apisix.apache.org/v1 kind: ApisixService # apisix service metadata: name: httpserver spec: upstream: httpserver # upstream = default/httpserver (namespace/upstreamName) port: 8080 # set port on service plugins: - name: aispeech-chash enable: true config: uri_args: - "userId" - "productId|deviceName" key: "apisix-chash-key" EOF
ApisixService
supports plug-ins similar to ApisixRoute
.
kubectl apply -f - <<EOF apiVersion: apisix.apache.org/v1 kind: ApisixUpstream # apisix upstream metadata: name: httpserver # default/httpserver spec: ports: - port: 8080 loadbalancer: type: chash hashOn: header key: hello EOF
Now, you can try to modify these yaml according to the CRD format and see if it will be synchronized to Apache APISIX.
Enjoy! If you have any questions, please report to the issue.