Kong Ingress Controller on Kubernetes

    安装

    使用 helm 安装

    helm repo add kong https://charts.konghq.com
    helm repo update
    
    # Helm 3
    helm install kong/kong --generate-name --set ingressController.installCRDs=false -n kong --create-namespace
    

    安装日志

    root@l2:~# helm repo add kong https://charts.konghq.com
    "kong" has been added to your repositories
    root@l2:~# helm repo update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "kubernetes-dashboard" chart repository
    ...Successfully got an update from the "nfs-subdir-external-provisioner" chart repository
    ...Successfully got an update from the "kong" chart repository
    ...Successfully got an update from the "azure" chart repository
    ...Successfully got an update from the "bitnami" chart repository
    Update Complete. ⎈Happy Helming!root@l2:~# helm install kong/kong --generate-name --set ingressController.installCRDs=false -n kong --create-namespace
    NAME: kong-1677205129
    LAST DEPLOYED: Fri Feb 24 10:18:59 2023
    NAMESPACE: kong
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    NOTES:
    To connect to Kong, please execute the following commands:
    
    HOST=$(kubectl get svc --namespace kong kong-1677205129-kong-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    PORT=$(kubectl get svc --namespace kong kong-1677205129-kong-proxy -o jsonpath='{.spec.ports[0].port}')
    export PROXY_IP=${HOST}:${PORT}
    curl $PROXY_IP
    
    Once installed, please follow along the getting started guide to start using
    Kong: https://docs.konghq.com/kubernetes-ingress-controller/latest/guides/getting-started/
    

    验证安装

    1. kubectl get svc -n kong 查找 LoadBalancer 的外部映射端口
    2. curl localhost:31897 -i 根据找到的端口进行验证

    安装日志

    root@l2:~# kubectl get svc -n kong
    NAME                                      TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
    kong-1677205129-kong-proxy                LoadBalancer   10.105.104.5   <pending>     80:31897/TCP,443:31968/TCP   4m3s
    kong-1677205129-kong-validation-webhook   ClusterIP      10.102.91.37   <none>        443/TCP                      4m3s
    root@l2:~# curl localhost:31897 -i
    HTTP/1.1 404 Not Found
    Date: Fri, 24 Feb 2023 02:24:36 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Content-Length: 48
    X-Kong-Response-Latency: 0
    Server: kong/3.1.1
    
    {"message":"no Route matched with those values"}
    

    以下来自 chatGPT 回答

    March 27th 2023, 2:10:05 pm


    Model: GPT-4

    Question :

    安装 kong 网关 1.x

    Answer :

    Kong是一款开源的API网关,用于API和微服务的管理。下面是如何在Linux系统(以Ubuntu为例)上安装Kong网关1.x版本的步骤:

    1. 添加Kong的仓库:

    bashCopy code

    curl -fsSL https://kong.bintray.com/kong-deb/download_file?file_path=kong-1.5.1.trusty.all.deb -o kong-1.5.1.trusty.all.deb
    
    1. 更新包列表:

    bashCopy code

    sudo apt-get update
    
    1. 安装依赖:

    bashCopy code

    sudo apt-get install -y openssl libpcre3 procps perl
    
    1. 安装Kong:

    bashCopy code

    sudo dpkg -i kong-1.5.1.trusty.all.deb
    
    1. 配置Kong: 首先,创建一个名为kong.conf的配置文件:

    bashCopy code

    sudo cp /etc/kong/kong.conf.default /etc/kong/kong.conf
    

    接下来,打开配置文件并配置数据库。Kong支持PostgreSQL和Cassandra。这里以PostgreSQL为例。将pg_host的值设置为你的PostgreSQL数据库地址,pg_userpg_password分别设置为数据库的用户名和密码:

    makefileCopy code

    pg_host = 127.0.0.1
    pg_user = kong
    pg_password = kong_password
    
    1. 初始化Kong数据库:

    bashCopy code

    kong migrations bootstrap [-c /path/to/your/kong.conf]
    
    1. 启动Kong:

    bashCopy code

    sudo kong start [-c /path/to/your/kong.conf]
    
    1. 检查Kong是否在运行:

    bashCopy code

    curl -i http://localhost:8001/
    

    如果你看到了Kong的版本信息,那么恭喜,Kong已成功安装并运行。现在你可以开始使用Kong管理你的API和微服务了。

    这里提供的是Kong 1.5.1版本的安装过程。如果你想安装其他1.x版本,请修改第1步中的下载链接以及第4步中的安装包名称。

    Question :

    在 kubernetes 安装 kong 网关 1.x

    Answer :

    在Kubernetes上安装Kong 1.x版本,可以使用Kong的Helm Chart进行部署。以下是使用Helm在Kubernetes上安装Kong 1.x版本的步骤:

    1. 首先,确保你已经安装了kubectlhelm。如果还没有,请参考以下链接进行安装:
    1. 添加Kong的Helm仓库:

    bashCopy code

    helm repo add kong https://charts.konghq.com
    
    1. 更新Helm仓库:

    bashCopy code

    helm repo update
    
    1. 创建一个命名空间(可选):

    bashCopy code

    kubectl create namespace kong
    
    1. 在Kubernetes上部署Kong 1.x版本(以1.5.1版本为例)。如果在第4步创建了命名空间,请确保在命令中使用--namespace kong选项。

    bashCopy code

    helm install kong/kong --version 1.5.1 --generate-name [--namespace kong]
    
    1. 确认Kong的Pod和服务已成功部署:

    bashCopy code

    kubectl get pods [--namespace kong]
    kubectl get services [--namespace kong]
    

    现在,Kong 1.x已经在你的Kubernetes集群上成功部署。你可以根据需要配置Kong的设置,例如使用Ingress资源来暴露Kong的服务。详细配置信息请参考Kong的官方文档:https://docs.konghq.com/kubernetes-ingress-controller/1.1.x/guides/getting-started/

    Question :

    在 kubernetes 安装 kong gateway 1.x (基于 postgres)

    Answer :

    要在Kubernetes上安装基于PostgreSQL的Kong Gateway 1.x(以1.5.1版本为例),请遵循以下步骤:

    1. 确保已经安装了kubectlhelm。如果还没有,请参考以下链接进行安装:

    2. 添加Kong的Helm仓库:

    bashCopy code

    helm repo add kong https://charts.konghq.com
    
    1. 更新Helm仓库:

    bashCopy code

    helm repo update
    
    1. 创建一个命名空间(可选):

    bashCopy code

    kubectl create namespace kong
    
    1. 安装PostgreSQL数据库。在这里,我们使用Bitnami的PostgreSQL Helm Chart进行部署。为了简化安装过程,你可以将PostgreSQL的用户名、密码和数据库名称设置为“kong”:

    bashCopy code

    helm repo add bitnami https://charts.bitnami.com/bitnami
    helm install postgresql --set postgresqlUsername=kong,postgresqlPassword=kong,postgresqlDatabase=kong [--namespace kong] bitnami/postgresql
    
    1. 获取PostgreSQL的服务名称,以便稍后在Kong的配置中使用:

    bashCopy code

    export POSTGRES_SERVICE=$(kubectl get svc --namespace kong -l "app.kubernetes.io/name=postgresql" -o jsonpath="{.items[0].metadata.name}")
    
    1. 在Kubernetes上部署Kong 1.x版本(以1.5.1版本为例)。如果在第4步创建了命名空间,请确保在命令中使用--namespace kong选项。同时,我们需要配置Kong的数据库连接信息:

    bashCopy code

    helm install kong/kong --version 1.5.1 --generate-name --set env.database=postgres --set env.pg_host=$POSTGRES_SERVICE --set env.pg_user=kong --set env.pg_password=kong --set env.pg_database=kong [--namespace kong]
    
    1. 确认Kong的Pod和服务已成功部署:

    bashCopy code

    kubectl get pods [--namespace kong]
    kubectl get services [--namespace kong]
    

    现在,Kong Gateway 1.x(基于PostgreSQL)已经在你的Kubernetes集群上成功部署。你可以根据需要配置Kong的设置,例如使用Ingress资源来暴露Kong的服务。详细配置信息请参考Kong的官方文档:https://docs.konghq.com/kubernetes-ingress-controller/1.1.x/guides/getting-started/

    评论栏