Environment Variable Configuration

In addition to the environment variables set by the user, the platform will also inject some useful environment variables by default. In addition, some new experimental features may also be enabled or set based on setting special environment variables. Therefore, understanding Kato’s default environment variable mechanism can enable developers to develop more efficiently in many scenarios and produce applications that are more suitable for Kato to run.

Default Injected Environment Variables

Generally, relevant variables are injected according to the relevant properties of the component to facilitate developers to obtain component-related information.

Variable nameVariable valueDescription
PORTThe first port number set by the applicationTry to obtain the value of the PORT environment variable for monitoring when the application establishes port monitoring
PROTOCOLhttp\tcp\mysql, etc.Protocol type corresponding to the above port
SERVICE_IDApplication IDApplication ID
MEMORY_SIZEmicro, small, medium, large, 2xlarge, etc., see below for the corresponding relationshipIndicates the memory size setting of the current application instance, generally used for the initialization of application memory-related settings, such as JAVA_OPTS
SERVICE_POD_NUMNumber of application instancesNumber of application instances
DEPEND_SERVICEserviceAlias:serviceID,Dependent application
HOST_IPip addressIP address of the host where the component is running
POD_IPip addressIP address when the component is running
DISCOVER_URLhttp://xxxxxxx/v1/resources/xxxConfigure the discovery interface address, the plug-in operating environment is valid
DISCOVER_URL_NOHOST/v1/resources/xxxConfiguration discovery URL without IP address, the address uses HOST_IP: 6100
  • The relationship between the component instance memory setting size and the value of the MEMORY_SIZE environment variable

    It is very useful for the program to obtain the memory size of the current component settings, such as the JVM configuration of Java, the fpm configuration of PHP, etc. Some internal middleware that needs to set the memory should preferably be coordinated with the memory setting of the component itself, otherwise OOM or memory may incur a wasteful situation.

    Memory/MbEnvironment Variable Value
  • Description of environment variables automatically injected by domain name:

The application defaults to inject the access domain name environment variable information of the current component: DOMAIN and DOMAIN_PROTOCOL. If the component has multiple ports, the injection strategy is as follows

  1. If there are multiple ports, _? port number will be added after the environment variable name, that is, DOMAIN_? port number. For example: DOMAIN_80, DOMAIN_8080

The corresponding domain name agreement is DOMAIN_PROTOCOL_80

  1. The value of the DOMIAN variable is the component port number from small to large, and the custom domain name takes precedence. For example, there are ports 80 and 8080. If 8080 is bound to a custom domain name, the value of DOMIAN is the custom domain name of port 8080. If no custom domain name is bound, it is the default domain name of port 80.

Variables Used When Building Components

The environment variables whose variable names begin with BUILD_ take effect during the construction phase of source code building applications, such as the following variables:

Variable nameVariable valueDescription
BUILD_REPARSEtrueRe-identify code language type when building
NO_CACHEtrueDo not use cache package when building
BUILD_MAVEN_CUSTOM_OPTS-DskipTests=true -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=trueFor maven build, the default value is as before
BUILD_MAVEN_CUSTOM_GOALSclean installFor maven build, the default value is as before

For more component build environment settings, please refer to Component Build Source Configuration

Application Runtime Function Control Variables

Environment variables beginning with ES_ will be used as extended function variables, for example, the following use case:

Variable nameVariable valueDescription
ES_SELECTNODESelect the ID of the hostUsed for fixed-point scheduling, specify scheduling to a host, the ID of the node can be obtained through grctl node list
ES_HOSTNETWORKtrueWhether to use host port mapping, please use this variable with caution
ES_HOSTNAMEHost nameSet the host name of the instance, suitable for single instance components
ES_CPULIMIT1 core=1000CPU limit value of custom components 5.0.3 and later versions support
ES_CPUREQUEST1 core=1000CPU request value of custom components 5.0.3 and later versions support
ES_TCPUDP_MESH_MEMORYMBCustomize the default MESH container memory limit, the default is 128MB
ES_TCPUDP_MESH_CPU1 core=1000Customize the default MESH container CPU limit, the default is 120, the minimum is 120

Effective Use of Environment Variables for Software Configuration

The third point of the 12 elements of cloud native applications: “Code and configuration are strictly separated, configuration must be completely separated from code, and different environments share a set of codes. It is recommended to store application configuration in environment variables.” It is recommended to make the parts of your program that need to be configured as variable as possible.