- Kubernetes Design Patterns and Extensions
- Onur Yilmaz
- 222字
- 2021-07-23 16:57:38
Initialization Pattern
Initialization is a widespread pattern in every part of software engineering, including programming languages and operating systems. In order to handle the initialization of an application in Kubernetes, initialization containers are proposed. Initialization containers, namely initContainers, are part of a pod's definition. Separation of concerns is handled by separating the life cycles of containers:
- Init containers
- Main containers
Containers that are defined as initContainers are executed for completion one by one, and they are all expected to exit successfully. After successful completion, the main containers are started. Some of the example uses of startup containers are as follows:
- To create configuration files
- To wait and ensure dependency services are available
- To create volumes and prepare files
- To register services to discovery systems
In the following activity, a web server will be installed in Kubernetes. As expected, there should be at least one container running the web server. However, there is an additional requirement of changing the served files before the web server starts. The life cycle of these operations is separated into the initialization container and the main container. These containers could have different container images and executables; however, they are expected to work on a shared resource. Life cycle separation and working together issues are handled in the following activity, and the initialization pattern is implemented in Kubernetes.