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 Name | Data Type | Required | Description |
---|---|---|---|
ssl | boolean | No | Whether to enable SSL connection, default is false |
disable_ssl_verify | boolean | No | Whether to disable SSL verification, default is false |
enable_checker | boolean | No | Whether to enable health check, default is false |
k8s_services | array | Yes | List of Kubernetes services |
checker | object | No | Health check configuration, only valid when enable_checker is true |
k8s_services Configuration
Parameter Name | Data Type | Required | Description |
---|---|---|---|
k8s_name | string | Yes | Kubernetes cluster name |
k8s_namespace | string | Yes | Kubernetes namespace |
k8s_service | string | Yes | Kubernetes service name |
k8s_service_port | integer | Yes | Kubernetes service port |
checker Configuration
The configuration contains multiple parameters defining how health checks are performed. The main parameters include:
Parameter Name | Data Type | Description |
---|---|---|
type | string | Health check type, such as “http”, “https”, “tcp”, “mysql”, “postgresql” |
interval | integer | Check interval |
timeout | integer | Timeout duration |
fall | integer | Consecutive failure threshold |
rise | integer | Consecutive success threshold |
http_req_method | string | HTTP request method |
http_req_uri | string | HTTP request URI |
valid_statuses | array | List 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
Each application Kubernetes upstream must have a unique name.
k8s_name
must be a Kubernetes cluster name already defined in the tool.k8s_service_port
must be a valid port number (1-65535).If a health check is enabled (
enable_checker: true
), a valid ‘checker’ configuration must be provided.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.
When importing configurations, the tool checks their validity before performing add or update operations.
If an upstream is removed from the configuration, the tool will automatically remove it from the application.
If an error occurs during configuration processing, the tool will automatically clear the changes made to maintain configuration consistency.
When exporting configurations, the tool converts Kubernetes cluster IDs to cluster names to improve the configuration’s readability and portability.
When exporting configurations, the tool will provide a warning message if the application does not exist.