Apache APIs IX provides KubeSphere with better gateway and K8S Ingress Controller

Introduction to KubeSphere

KubeSphere is a cloud oriented native application system built on Kubernetes. IT is completely open source, supports multi cloud and multi cluster management, provides full stack IT automatic operation and maintenance capability, and simplifies the DevOps workflow of enterprises. Its architecture makes IT very convenient for third-party applications to plug and play with cloud native ecological components.

As a full stack multi tenant container platform, KubeSphere provides an operation and maintenance friendly wizard operation interface to help enterprises quickly build a powerful and feature rich container cloud platform. KubeSphere provides users with many functions required to build an enterprise class Kubernetes environment, such as multi cloud and multi cluster management, Kubernetes resource management, DevOps, application lifecycle management, micro service governance (service grid), log query and collection, service and network, multi tenant management, monitoring alarm, event and audit query, storage management, access control GPU support, network policy, image warehouse management and security management.

Introduction to Apache APIs IX

Apache APIs IX is an open source, high-performance, dynamic cloud native gateway. It was donated to Apache foundation by Shenzhen Branch Technology Co., Ltd. in 2019. At present, it has become the top open source project of Apache foundation and the most active gateway project on GitHub. Apache APIs IX currently covers many scenarios, such as API gateway, LB, Kubernetes Ingress, Service Mesh, etc.

Preconditions

The existing Kubernetes cluster has been incorporated into KubeSphere management.

Deploying Apache APIs IX and Apache APIs IX Progress Controller

We can refer to KubeSphere's documentation to enable KubeSphere's Appstore( https://KubeSphere.io/docs/pluggable-components/app-store/ ), or use the Helm repository of Apache APIs IX for deployment. Here, we directly use the Helm repository of Apache APIs IX for deployment.

Execute the following command to add the Helm repo of Apache APIs IX and complete the deployment.

➜  ~ helm repo add apisix https://charts.apiseven.com
"apisix" has been added to your repositories
➜  ~ helm repo add bitnami https://charts.bitnami.com/bitnami 
"bitnami" has been added to your repositories
➜  ~ helm repo update
➜  ~ kubectl create ns apisix
namespace/apisix created
➜  ~ helm install apisix apisix/apisix --set gateway.type=NodePort --set ingress-controller.enabled=true --namespace apisix  
W0827 18:19:58.504653  294386 warnings.go:70] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
NAME: apisix
LAST DEPLOYED: Fri Aug 27 18:20:00 2021
NAMESPACE: apisix
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace apisix -o jsonpath="{.spec.ports[0].nodePort}" services apisix-gateway)
  export NODE_IP=$(kubectl get nodes --namespace apisix -o jsonpath="{.items[0].status.addresses[0].address}")
  echo http://$NODE_IP:$NODE_PORT

Verify that has been successfully deployed and running:

➜  ~ kubectl -n apisix get pods 
NAME                                         READY   STATUS    RESTARTS   AGE
apisix-77d7545d4d-cvdhs                      1/1     Running   0          4m7s
apisix-etcd-0                                1/1     Running   0          4m7s
apisix-etcd-1                                1/1     Running   0          4m7s
apisix-etcd-2                                1/1     Running   0          4m7s
apisix-ingress-controller-74c6b5fbdd-94ngk   1/1     Running   0          4m7s

You can see that the relevant pods are running normally.

Deploy sample project

We use Kenneth Reitz / httpbin as a sample project for demonstration. The deployment is also completed directly in KubeSphere.

Select service – stateless service, and you can create it.


You can see the successful deployment in the service and load interface of KubeSphere, or you can directly check whether the deployment has been successful under the terminal.

➜  ~ kubectl get pods,svc -l app=httpbin
NAME                             READY   STATUS    RESTARTS   AGE
pod/httpbin-v1-7d6dc7d5f-5lcmg   1/1     Running   0          48s

NAME              TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/httpbin   ClusterIP   10.96.0.5    <none>        80/TCP    48s

Use Apache APIs IX as the gateway proxy

Let's first demonstrate how to use Apache APIs IX as a gateway proxy for services in the Kubernetes cluster.

root@apisix:~$ kubectl -n apisix exec -it `kubectl -n apisix get pods -l app.kubernetes.io/name=apisix -o name` -- bash
bash-5.1# curl httpbin.default/get
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.default", 
    "User-Agent": "curl/7.77.0"
  }, 
  "origin": "10.244.2.9", 
  "url": "http://httpbin.default/get"
}

You can see that the sample project can be accessed normally in the Pod of Apache APIs IX. Next, use Apache APIs IX to proxy the sample project.

Here, we use curl to call the admin interface of Apache APIs IX to create a route. Forward all requests with the host header httpbin.org to the actual application service httpbin.default:80.

bash-5.1# curl "http://127.0.0.1:9180/apisix/admin/routes/1" -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" -X PUT -d '
{
  "uri": "/get",
  "host": "httpbin.org",
  "upstream": {
    "type": "roundrobin",
    "nodes": {
      "httpbin.default:80": 1
    }
  }
}'
{"node":{"key":"\/apisix\/routes\/1","value":{"host":"httpbin.org","update_time":1630060883,"uri":"\/*","create_time":1630060883,"priority":0,"upstream":{"type":"roundrobin","pass_host":"pass","nodes":{"httpbin.default:80":1},"hash_on":"vars","scheme":"http"},"id":"1","status":1}},"action":"set"}

You will get an output similar to the above. Next, verify whether the agent is successful:

bash-5.1# curl http://127.0.0.1:9080/get -H "HOST: httpbin.org"
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.77.0", 
    "X-Forwarded-Host": "httpbin.org"
  }, 
  "origin": "127.0.0.1", 
  "url": "http://httpbin.org/get"
}

Get the above output, indicating that the traffic of the sample project has been proxy through Apache APIs IX. Next, let's try to access the sample project outside the cluster through Apache APIs IX.

root@apisix:~$ kubectl  -n apisix get svc -l app.kubernetes.io/name=apisix
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
apisix-admin     ClusterIP   10.96.33.97    <none>        9180/TCP       22m
apisix-gateway   NodePort    10.96.126.83   <none>        80:31441/TCP   22m

When deploying with Helm chart, the port of Apache APIs IX will be exposed in the form of NodePort by default. We use the port of Node IP + NodePort for access test.

root@apisix:~$ curl http://172.18.0.5:31441/get -H "HOST: httpbin.org" 
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.76.1", 
    "X-Forwarded-Host": "httpbin.org"
  }, 
  "origin": "10.244.2.1", 
  "url": "http://httpbin.org/get"
}

It can be seen that outside the cluster, Apache apisid can be used as the gateway agent for the services in Kubernetes cluster.

Using apisik ingress controller proxy service

We can directly add application routing (Ingress) in KubeSphere. Apache apifix ingress controller will automatically synchronize the routing rules to Apache apiix to complete the proxy of the service.

Note that we have added the annotation configuration of kubernetes.io/ingress.class: apifix to support the scenario of multiple ingress controllers in the cluster.

After saving, you can see the following interface:

Test whether the agent succeeds under the terminal:

root@apisix:~$ curl http://172.18.0.5:31441/get -H "HOST: http-ing.org"  
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "http-ing.org", 
    "User-Agent": "curl/7.76.1", 
    "X-Forwarded-Host": "http-ing.org"
  }, 
  "origin": "10.244.2.1", 
  "url": "http://http-ing.org/get"
}

You can see the normal agent.

In addition to the above methods, Apache apifix ingress controller extends Kubernetes through CRD. You can also complete the external exposure of services in Kubernetes by publishing user-defined resources such as ApisixRoute.

summary

You can use the official Helm warehouse of Apache APIs IX in KubeSphere to directly deploy Apache APIs IX and APIs IX progress controller. In addition, Apache APIs IX can be used as a gateway or the data surface of APIs IX ingress controller to carry business traffic.

Future outlook

Apache APIs IX has reached cooperation with KubeSphere community. You can find Apache APIs IX directly in KubeSphere's own application repository without adding Helm repository manually.

About Apache APIs IX

Apache APISIX is a dynamic, real-time, high-performance open source API gateway, which provides rich traffic management functions such as load balancing, dynamic upstream, gray publishing, service fusing, identity authentication, observability and so on. Apache APIs IX can help enterprises process API and micro service traffic quickly and safely, including gateway, Kubernetes Ingress and service grid.

Hundreds of enterprises around the world have used Apache APISIX to handle key business traffic, including finance, Internet, manufacturing, retail, operators, etc., such as NASA, European Union digital factory, China aerospace, China Mobile, Tencent, Huawei, microblog, Netease, shell search, 360, Taikang, Naixue's tea, etc.

More than 200 contributors have jointly created Apache APIs IX, the world's most active open source gateway project. Smart developers! Join this active and diverse community and bring more beautiful things to the world!

  • Apache APISIX GitHub: https://github.com/apache/apisix
  • Apache APIs IX official website: https://apisix.apache.org/
  • Apache APIs IX documentation: https://apisix.apache.org/zh/docs/apisix/getting-started

Keywords: Operation & Maintenance Apache gateway

Added by fredouille on Fri, 17 Sep 2021 14:04:08 +0300