Advanced environment variable configuration

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

Default injected environment variables

Generally, the relevant variables are injected according to the relevant properties of the component, so as to facilitate the developer to obtain the information related to the component.

variable namevariableillustrate
PORTThe first port number set by the applicationWhen the application establishes port monitoring, try to obtain the value of the PORT environment variable for monitoring
PROTOCOLhttp\tcp\mysql etc.The protocol type corresponding to the above port
TENANT_IDTenant IDTenant ID
SERVICE_IDApp IDApp ID
MEMORY_SIZEmicro, small, medium, large, 2xlarge, etc. See below for the correspondenceIndicates 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 addressThe IP address of the host where the component is running
POD_IPip addressIP address of the component runtime
DISCOVER_URLhttp://xxxxxxx/v1/resources/xxxConfigure the discovery interface address, the plugin running environment is valid
DISCOVER_URL_NOHOST/v1/resources/xxxConfigure discovery URL without IP address, use HOST_IP:6100
  • The relationship between the component instance memory setting size and the value of the MEMORY_SIZE environment variable

    It is very beneficial for the program to obtain the memory size set by the current component, such as Java’s JVM configuration, PHP’s fpm configuration, etc. Some internal middleware that needs to set memory should preferably be coordinated with the memory settings of the component itself, otherwise OOM or memory waste may occur. Case.

    | memory/Mb | environment variable value | | ———- | ————— | | 128 | micro | | 256 | small | | 512 | medium | | 1024 | large | | 2048 | 2xlarge | | 4096 | 4xlarge | | 8192 | 8xlarge | | 16384 | 16xlarge | | 32768 | |

  • Description of environment variables for automatic domain name injection:

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

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

The corresponding domain name protocol 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 with 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 the component

Environment variables whose variable names start withBUILD_take effect in the construction phase of the source code construction class application, such as the following variable:

variable namevariableillustrate
BUILD_REPARSEtrueRe-identify code language type at build time
NO_CACHEtrueBuild without cached packages
BUILD_MAVEN_CUSTOM_OPTS-DskipTests=true -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=trueFor maven builds, defaults as before
BUILD_MAVEN_CUSTOM_GOALSclean installFor maven builds, defaults as before

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

Application Runtime Function Control Variables

Environment variables starting withES_will be used as extended function variables, such as the following use case:

variable namevariableillustrate
ES_SELECTNODESelect host IDUsed for fixed-point scheduling, specify scheduling to a host, and the node ID can be obtained through grctl node list
ES_HOSTNETWORKtrueWhether to use host port mapping, please use this variable with caution
ES_HOSTNAMECPU nameSet the hostname of the instance, for single-instance components
ES_CPULIMIT1 core=1000CPU limit values for custom components are supported in version 5.0.3 and later
ES_CPUREQUEST1 core=1000CPU request values for custom components are supported in version 5.0.3 and later
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
ES_HOST_DOMAINNAMEIP addressCustomize domain name resolution, generate a resolution record corresponding to DOMAINNAME to IP address in /etc/hosts
ES_DISABLE_SIDECAR_CHECKtrueTurn off the port detection of the dependent service by the MESH plugin, even if the corresponding port of the dependent component is not ready, it will still start its own component

Efficient 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 code.It is recommended to store application configuration in environment variables”.It is recommended that the parts of your program that need to be configured be as variable as possible in the environment.