Deploy mesh proxies in native sidecar mode

Updated at:

Service Mesh (ASM) supports deploying mesh proxies for applications in a cluster in sidecar mode or sidecarless mode to enable abstracted management of underlying network capabilities, such as load balancing, service discovery, traffic shaping, enhanced security, and traffic observability. In sidecar mode, ASM adds the mesh proxy container to a pod, so that the mesh proxy container and the application container are deployed in the same pod and share the same network namespace. This enables the mesh proxy to transparently intercept and process the inbound and outbound traffic of the application container. This topic describes how to deploy mesh proxies in native sidecar mode in ASM.

Traditional sidecar and native sidecar

Comparison item

Traditional sidecar

Native sidecar

Supported Kubernetes versions

Community Kubernetes 1.4 to 1.28, or ACK, ACK Serverless, or Container Compute Service (ACS) clusters earlier than 1.30.

Community Kubernetes 1.29 or later. ACK, ACK Serverless, or ACS clusters must be 1.30 or later.

Supported ASM versions

ASM instances earlier than 1.22.

ASM 1.22 or later deploys the mesh proxy in native sidecar mode by default. This applies when the added Kubernetes cluster is 1.30 or later (an ACK, ACK Serverless, or ACS cluster).

Deployment method

Both the sidecar container and the main container are configured under the containers field.

The sidecar container is configured in the initContainers field, and the restartPolicy: Always field is present.

Lifecycle

Cannot be synchronized with the main container and must be managed separately.

Synchronized with the main container, with no additional configuration required.

In traditional sidecar mode, the mesh proxy is actually deployed as a regular container in the pod together with the application container, and each of them has its own lifecycle. This can cause the following known issues:

  • If the application container starts faster than the sidecar proxy container, the application container cannot access the network. This issue can be resolved by configuring graceful sidecar startup, but problems may still occur when the sidecar proxy starts slowly.

  • If the sidecar proxy container shuts down before the application container, the application container cannot access the network. This issue can be resolved by configuring graceful sidecar termination, but this may prolong the pod termination time.

  • If a Job-type application container exits after it finishes running, the sidecar proxy container continues to run and keeps the pod running indefinitely.

  • The initContainers that run before the sidecar proxy container starts cannot access the network. This issue can usually be worked around by excluding some egress traffic from passing through the sidecar proxy. For more information, see Address ranges excluded from outbound traffic interception.

How do I check whether a mesh proxy is deployed in native sidecar mode?

If the initContainers field of a pod contains the istio-proxy container and the container configuration includes the restartPolicy: Always field, the mesh proxy is deployed in native sidecar mode. For example:

apiVersion: v1
kind: Pod
metadata:
  name: sleep-xxxxxxxx-xxxxx
  namespace: default
spec:
  containers:
...
      image: 'registry.cn-hangzhou.aliyuncs.com/acs/curl:8.1.2'
      imagePullPolicy: IfNotPresent
      name: sleep
...
  initContainers:
...  
      image: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/proxyv2:v1.22.2.35-ge64ec8af-aliyun
      imagePullPolicy: IfNotPresent
      name: istio-proxy
      ports:
        - containerPort: 15090
          name: http-envoy-prom
          protocol: TCP
      restartPolicy: Always  # The presence of this field indicates deployment in native sidecar mode
...

In native sidecar mode, all sidecar proxy configurations related to the sidecar proxy lifecycle become ineffective (because the native sidecar no longer requires these configurations). For more information, see Configure sidecar proxies.

How do I switch back to traditional sidecar proxy deployment mode?

If your cluster also runs MutatingWebhook components that depend on older Kubernetes versions and modify pod definitions (such as the KubeSphere logsidecar-injector), these components may delete the native sidecar definition, which may cause creation failures. You may need to switch back to traditional sidecar proxy deployment mode to maintain compatibility with older versions of MutatingWebhook.

Perform the following steps:

  1. Use kubectl to connect to the ASM instance. For more information, see Access Istio resources through kubectl on the control plane.

  2. Append the configuration to the asmmeshconfig resource.

    kubectl patch asmmeshconfig default --type=merge --patch='{"spec":{"enableNativeSidecar":false}}'

    Expected output:

    asmmeshconfig.istio.alibabacloud.com/default patched
  3. Manually restart the pod. For more information, see Redeploy a workload.

  4. View the pod information again.

    kubectl get pod sleep-xxxxxxxx-xxxxx -o yaml

    Expected output:

    apiVersion: v1
    kind: Pod
    metadata:
      name: sleep-xxxxxxxx-xxxxx
      namespace: default
    spec:
      containers:
    ...  
          image: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/proxyv2:v1.22.2.35-ge64ec8af-aliyun      
          name: istio-proxy
          ports:
            - containerPort: 15090
              name: http-envoy-prom
              protocol: TCP
    ...
          image: 'registry.cn-hangzhou.aliyuncs.com/acs/curl:8.1.2'
          imagePullPolicy: IfNotPresent
          name: sleep
    ...

    The sidecar container istio-proxy is no longer under initContainers, but is configured together with the main container under containers.