Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Time:2021-10-25

Introduction to kubesphere

Kubesphere is a deep cloud native application system built in kubernetes. It is completely open source, supports multi cloud and multi cluster management automation, provides full stack it operation and maintenance capabilities, and simplifies the Devops workflow of enterprises. Its architecture can easily integrate applications with cloud native ecological components for plug and play (plug and play).

It is a multi pipe container platform of the whole stack. Kubesphere provides an operation and maintenance friendly shape operation interface to help enterprises build a powerful container with special functions. Kubesphere provides users with the reporting function required to build an enterprise class kubernetes environment, including multi cloud and multi cluster management, kubernetes management, Devops, life cycle management, micro service management (service grid), and collection, service and network, multi insight management, monitoring resource logs, events and audit, storage query management, access control, GPU support, network policy Supervision and management, safety management, etc.

Introduction to Apache APIs IX

Apache apisid is a pseudo open source and dynamic cloud native gateway. It was donated to Apache foundation by Shenzhen tributary Technology Co., Ltd. in 2019. It has become a popular project of Apache foundation and the latest portal project on GitHub. Apache APIs IX has covered API gateway, LB, kubernetes ingress, service mesh and other scenarios.

Post condition

Update the existing kubernetes cluster to 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/pl…), or use the helm repository of Apache APIs IX for development. Here, we directly use the helm repository of Apache APIs IX for deployment.

Execute the following command to add helm repo of Apache apisid 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 the has been successfully implemented 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.

Deployment demonstration project

Wekennethreitz/httpbinUse as an example project for demonstration. The deployment is also completed directly in kubesphere.

Select service – stateless service, easy to create.

Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Visual deployment is successful on the service and load interface of kubesphere, or you can directly check whether it has been successfully deployed 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 as the gateway proxy

Let’s first demonstrate how to use Apache apiix as a gateway proxy for services in kubernetes.

[email protected]:~$ 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 the normally accessed sample project in the pod of Apache APIs IX. The following is a proxy using the sample project of Apache APIs IX.

Here we usecurlCall the admin interface of Apache APIs IX to create a route. Set all host headers tohttpbin.orgForward your request tohttpbin.default:80This is a practical application service.

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.

[email protected]:~$ 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.

[email protected]:~$ 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.

Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Notice that we addedkubernetes.io/ingress.class: apisixThe annotation configuration is used to support the scenario of multiple ingress controllers in the cluster.

After saving, you can see the following interface:

Apache APIs IX provides kubesphere with better gateway and k8s ingress controller

Test whether the agent succeeds under the terminal:

[email protected]:~$ 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 APIs IX ingress controller extends kubernetes through CRD. You can also publish kubernetes through CRDApisixRouteAnd other custom resources to complete the external exposure of services in kubernetes.

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!