部署方式

混合部署

Kong Gateway Operator 通过混合模式部署,负责部署和管理连接外部控制平面的 DataPlane 资源。
这个外部控制平面可以是 Kong Konnect 提供的,也可以是你自己搭建和管理的。

安装

Konnect

# 在应用这个配置之前,请先创建一个包含集群证书的 Secret。
# kubectl create secret tls konnect-client-tls -n kong --cert=./tls.crt --key=./tls.key
#  https://docs.konghq.com/gateway-operator/1.5.x/get-started/konnect/install/
echo "
kind: KonnectExtension
apiVersion: gateway-operator.konghq.com/v1alpha1
metadata:
  name: example-konnect-config
  namespace: kong
spec:
  controlPlaneRef:
    type: konnectID
    konnectID: <CP_ID>
  controlPlaneRegion: <REGION>
  serverHostname: <HOSTNAME>
  konnectControlPlaneAPIAuthConfiguration:
    clusterCertificateSecretRef:
      name: konnect-client-tls
---
apiVersion: gateway-operator.konghq.com/v1beta1
kind: DataPlane
metadata:
  name: dataplane-example
  namespace: kong
spec:
  extensions:
  - kind: KonnectExtension
    name: example-konnect-config
    group: gateway-operator.konghq.com
  deployment:
    podTemplateSpec:
      spec:
        containers:
        - name: proxy
          image: kong/kong-gateway:3.10.0.1
          env:
          - name: KONG_LOG_LEVEL
            value: debug
" | kubectl apply -f -

Self Managed

# 在执行应用操作之前,请确保已创建一个包含集群证书的 Secret。
# kubectl create secret tls kong-cluster-cert -n kong --cert=./tls.crt --key=./tls.key

# 请注意,cluster_control_plane 的值会根据你的环境有所不同。
# control-plane-release-name 需要替换为你实际的控制平面发布名称,
# hybrid 则替换为它所在的命名空间。
echo "
apiVersion: gateway-operator.konghq.com/v1beta1
kind: DataPlane
metadata:
  name: dataplane-example
  namespace: kong
spec:
  deployment:
    podTemplateSpec:
      spec:
        containers:
        - name: proxy
          image: kong/kong-gateway:3.10.0.1
          env:
          - name: KONG_ROLE
            value: data_plane
          - name: KONG_DATABASE
            value: "off"
          - name: KONG_CLUSTER_CERT
            value: /etc/secrets/kong-cluster-cert/tls.crt
          - name: KONG_CLUSTER_CERT_KEY
            value: /etc/secrets/kong-cluster-cert/tls.key
          - name: KONG_LUA_SSL_TRUSTED_CERTIFICATE
            value: system
          - name: KONG_CLUSTER_CONTROL_PLANE
            value: control-plane-release-name-kong-cluster.hybrid.svc.cluster.local:8005
          - name: KONG_CLUSTER_TELEMETRY_ENDPOINT
            value: control-plane-release-name-kong-clustertelemetry.hybrid.svc.cluster.local:8006
          volumeMounts:
            - name: cluster-certificate
              mountPath: /var/cluster-certificate
            - name: kong-cluster-cert
              mountPath: /etc/secrets/kong-cluster-cert/
              readOnly: true
        volumes:
          - name: cluster-certificate
          - name: kong-cluster-cert
            secret:
              secretName: kong-cluster-cert
              defaultMode: 420
" | kubectl apply -f -

无数据库部署

Kong Gateway Operator 可以自动部署 Kong Ingress Controller 的控制平面和数据平面资源。
无数据库部署使用 Kubernetes Gateway API 来实现。你配置 GatewayClassGatewayGatewayConfiguration 对象,Kong Gateway Operator 会将这些配置转换成 Kong 特定的配置。

安装

echo "
kind: GatewayConfiguration
apiVersion: gateway-operator.konghq.com/v1beta1
metadata:
 name: kong
 namespace: default
spec:
 dataPlaneOptions:
   deployment:
     podTemplateSpec:
       spec:
         containers:
         - name: proxy
           image: kong/kong-gateway:3.10.0.1
 controlPlaneOptions:
   deployment:
     podTemplateSpec:
       spec:
         containers:
         - name: controller
           image: kong/kubernetes-ingress-controller:3.4.4
           env:
           - name: CONTROLLER_LOG_LEVEL
             value: debug
---
kind: GatewayClass
apiVersion: gateway.networking.k8s.io/v1
metadata:
 name: kong
spec:
 controllerName: konghq.com/gateway-operator
 parametersRef:
   group: gateway-operator.konghq.com
   kind: GatewayConfiguration
   name: kong
   namespace: default
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
 name: kong
 namespace: default
spec:
 gatewayClassName: kong
 listeners:
 - name: http
   protocol: HTTP
   port: 80
" | kubectl apply -f -

现在,你可以运行 kubectl get -n default gateway kong 来获取正在运行的网关的 IP 地址。

注意:如果你的集群无法创建 LoadBalancer 类型的服务,那么你获得的 IP 地址可能只能在集群内部路由。

配置网关

Gateway 资源包含了多个子组件,例如 ControlPlaneDataPlane,这些组件会代替它创建和管理。从更深的技术层面来看,ControlPlane 对应 Kong Ingress Controller,而 DataPlane 对应 Kong Gateway。

虽然这些子组件的配置不是主要用途,但你可以通过 GatewayConfiguration API 提供配置。这些配置可以包括子组件使用的容器镜像和镜像版本,还可以覆盖环境变量和卷挂载,这些设置将传递到为该组件创建的 Pods 中。

例如:

kind: GatewayConfiguration
apiVersion: gateway-operator.konghq.com/v1beta1
metadata:
 name: kong
 namespace: default
spec:
 dataPlaneOptions:
   deployment:
     podTemplateSpec:
       spec:
         containers:
         - name: proxy
           image: kong/kong-gateway:3.10.0.1
         env:
         - name: TEST_VAR
           value: TEST_VAL
 controlPlaneOptions:
   deployment:
     podTemplateSpec:
       spec:
         containers:
         - name: controller
           image: kong/kubernetes-ingress-controller:3.4.4
         env:
         - name: TEST_VAR
           value: TEST_VAL

像上面的配置可以在 API 上创建,但在被 GatewayClass 引用之前是不会生效的。

kind: GatewayClass
apiVersion: gateway.networking.k8s.io/v1
metadata:
 name: kong
spec:
 controllerName: konghq.com/gateway-operator
 parametersRef:
   group: gateway-operator.konghq.com
   kind: GatewayConfiguration
   name: kong
   namespace: default

通过在 GatewayClass 中使用 parametersRef 来绑定 GatewayConfiguration,这个配置会自动应用到所有为该类创建的 Gateway 资源,甚至会回溯到之前创建的那些 Gateway 资源。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容