In a Container Service for Kubernetes (ACK) cluster, Elastic Container Instance-based pods and the component that synchronizes Services are started and run in parallel. If the cluster contains a large number of Services and Service endpoints, the access to the pods may time out before the cluster IP address is synchronized among the Services. This topic describes how to configure a pod to be created after the cluster IP address is synchronized among Services in an ACK cluster. This ensures that the containers in the pod can access the Services without timeout errors.
Feature description
If you use Elastic Container Instance in Container Service for Kubernetes (ACK) clusters, pods and the component that synchronizes Services are started and run in parallel. If the ACK cluster contains a large number of Services and Service endpoints, a long period of time is required to synchronize the Services. If a container in the pod accesses a Service on which the cluster IP address is not synchronized, the access times out.
For example, in big data scenarios such as Apache Spark, a pod must access the driver or other Services immediately after the pod is created. If the cluster IP address of CoreDNS is not synchronized among the Services, the access to the Services times out and the task ends.
To resolve this issue, Elastic Container Instance allows the system to wait until the cluster IP address is synchronized among Services before the system creates a pod. This ensures that containers in the pod can access Services.
When you enable this feature, if the cluster contains a large number of Services and Service endpoints, the startup time of the pod is extended.
Configuration description
You can add an annotation to the metadata in the configuration file of a pod to configure the pod to be created after the cluster IP address is synchronized among Services. The annotation is k8s.aliyun.com/eci-wait-clusterip-ready
. If you set the value to *
, the pod is created after the cluster IP address is synchronized among Services.
Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.
To use features of Elastic Container Instance, you can add annotations only when you create Elastic Container Instance-based pods. If you add or modify annotations when you update pods, these annotations do not take effect.
Sample configurations
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx-test
labels:
app: nginx
annotations:
k8s.aliyun.com/eci-wait-clusterip-ready: "*" # The system does not start the pod until the cluster IP address is synchronized among Services.
spec:
containers:
- name: nginx
image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
ports:
- containerPort: 80