Application Kubernetes Upstreams

Directory Structure

|-- k8s_upstreams/
  |-- k8s_upstreams.yaml
  |-- ...

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

Configuration Description

Each application 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
sslbooleanNoWhether to enable SSL connection, default is false
disable_ssl_verifybooleanNoWhether to disable SSL verification, default is false
enable_checkerbooleanNoWhether to enable 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 configuration contains multiple parameters defining how health checks are performed. The main parameters include:

Parameter NameData TypeDescription
typestringHealth check type, such as “http”, “https”, “tcp”, “mysql”, “postgresql”
intervalintegerCheck interval
timeoutintegerTimeout duration
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

app_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
app_k8s_upstream_name2:
  ssl: true
  disable_ssl_verify: false
  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 application Kubernetes upstreams, one with health check enabled and another with SSL enabled but health check disabled.

Usage Example

Update configuration to OpenResty Edge:

edge-config https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -l k8s_upstreams -i /root/oredge-configs -d test.com

Export configuration from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -E -l k8s_upstreams -d test.com

Cleanup K8s upstreams from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -c -l k8s_upstreams -d test.com

The above examples all use -l k8s_upstreams to specify that the command-line tool will operate only on configurations related to the K8s upstreams.

Notes

  1. Each application Kubernetes upstream must have a unique name.

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

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

  4. If a health check is enabled (enable_checker: true), a valid ‘checker’ configuration must be provided.

  5. When updating configurations, the tool compares the new and old configurations to determine if an update is necessary. If there are changes, the tool will execute the update operation.

  6. When importing configurations, the tool checks their validity before performing add or update operations.

  7. If an upstream is removed from the configuration, the tool will automatically remove it from the application.

  8. If an error occurs during configuration processing, the tool will automatically clear the changes made to maintain configuration consistency.

  9. When exporting configurations, the tool converts Kubernetes cluster IDs to cluster names to improve the configuration’s readability and portability.

  10. When exporting configurations, the tool will provide a warning message if the application does not exist.