Global Kubernetes Upstreams

Directory Structure

|-- global_k8s_upstreams/
  |-- global_k8s_upstreams.yaml
  |-- ...

The YAML files can contain one or more global Kubernetes upstream configurations.

Configuration Description

Each global Kubernetes upstream configuration is a key-value pair, where the key is the upstream name and the value is an object containing the following parameters:

Parameter NameData TypeRequiredDescription
sslbooleanNoEnable SSL connection, default is false
disable_ssl_verifybooleanNoDisable SSL verification, default is false
enable_checkerbooleanNoEnable health check, default is false
k8s_servicesarrayYesList of Kubernetes services
checkerobjectNoHealth check configuration, only valid when enable_checker is true

k8s_services Configuration

Parameter NameData TypeRequiredDescription
k8s_namestringYesKubernetes cluster name
k8s_namespacestringYesKubernetes namespace
k8s_servicestringYesKubernetes service name
k8s_service_portintegerYesKubernetes service port

checker Configuration

The health check configuration contains multiple parameters to define how health checks are performed. Main parameters include:

Parameter NameData TypeDescription
typestringHealth check type, e.g., “http”
intervalintegerCheck interval
timeoutintegerTimeout
fallintegerConsecutive failure threshold
riseintegerConsecutive success threshold
http_req_methodstringHTTP request method
http_req_uristringHTTP request URI
valid_statusesarrayList of valid HTTP status codes

Configuration Example

global_k8s_upstream_name1:
  ssl: false
  disable_ssl_verify: false
  enable_checker: true
  k8s_services:
  - k8s_name: k8s_cluster_name1
    k8s_namespace: default
    k8s_service: test-hello
    k8s_service_port: 80
  - k8s_name: k8s_cluster_name1
    k8s_namespace: default
    k8s_service: test-hello-2
    k8s_service_port: 82
  checker:
    user_agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
    valid_statuses:
    - 200
    - 302
    rise: 2
    type: http
    fall: 3
    interval: 3
    timeout: 1
    http_req_method: GET
    http_req_host: test.com
    http_req_uri: /status
global_k8s_upstream_name2:
  ssl: true
  disable_ssl_verify: true
  enable_checker: false
  k8s_services:
  - k8s_name: k8s_cluster_name1
    k8s_namespace: default
    k8s_service: test-hello-2
    k8s_service_port: 82

This configuration defines two global Kubernetes upstreams, one with health checks enabled and another with SSL enabled but health checks disabled.

Usage Example

Update configuration to OpenResty Edge:

edge-config https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -l global_k8s_upstreams -i /root/oredge-configs

Export configuration from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -E -l global_k8s_upstreams

Both examples use -l global_k8s_upstreams to specify importing/exporting only global Kubernetes upstream related configurations.

Notes

  1. Global Kubernetes upstream is a global configuration. Delete operations are not performed when updating configurations to maintain compatibility with multiple local configurations.

  2. Each global Kubernetes upstream must have a unique name.

  3. k8s_name must be a Kubernetes cluster name already defined in the tool.

  4. k8s_service_port must be a valid port number (1-65535).

  5. If health checks are enabled (enable_checker: true), a valid checker configuration must be provided.

  6. When updating configurations, the tool compares new and old configurations to determine if an update is needed. If there are changes, an update operation will be performed.

  7. When importing configurations, the tool first checks the validity of the configuration before performing add or update operations.

  8. When exporting configurations, the tool converts Kubernetes cluster IDs to cluster names for better readability and portability of the configuration.