Sidecar CRD reference

更新时间:
复制 MD 格式

The Sidecar custom resource definition (CRD) describes the configuration of a Sidecar proxy attached to a workload. The proxy manages inbound and outbound communication for the workload. This topic describes the features, considerations, configuration examples, and fields for the Sidecar CRD.

Sidecar introduction

The Sidecar CRD defines the configuration for the Sidecar proxy, which mediates inbound and outbound communication for its attached workload instance. By default, Istio programs all Sidecar proxies in the mesh with the necessary configuration to reach every workload instance in the mesh and to accept traffic on all ports associated with the workload. The Sidecar configuration enables fine-tuning of the ports and protocols that the proxy supports for receiving and forwarding traffic to and from the workload. Additionally, a Sidecar can restrict the set of services that the proxy can access when forwarding outbound traffic from the workload.

A service mesh uses namespaces to manage services and configurations. A Sidecar configuration in a namespace is applied to workload instances in the same namespace using the workloadSelector field. If the workloadSelector field is absent, the Sidecar applies to all workload instances in that namespace. A Sidecar resource with a workloadSelector that selects a specific workload instance takes precedence over a Sidecar resource without a workloadSelector. If a more specific Sidecar is selected, the configuration from the namespace-wide Sidecar is completely ignored.

Considerations

  • Each namespace can have only one Sidecar configuration without a specified workloadSelector. This configuration specifies the default values for all pods in that namespace. Name the namespace-scoped Sidecar default.

    • If two or more Sidecar configurations without a selector exist in a given namespace, the system behavior is undefined.

    • If two or more Sidecar configurations with a workload selector select the same workload instance, the system behavior is undefined.

  • A Sidecar configuration in the MeshConfig root namespace is applied by default to all namespaces that do not have a Sidecar configuration. This global default Sidecar configuration must not include any workload selectors.

  • Sidecars do not apply to gateways, even though gateways are Istio proxies.

Configuration examples

Example 1: Global default Sidecar configuration

The following example declares a global default Sidecar configuration in the root namespace istio-config. This configuration configures Sidecars in all namespaces to allow egress traffic only to other workloads in the same namespace or to services in the istio-system namespace.

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: default
  namespace: istio-config
spec:
  egress:
  - hosts:
    - "./*"
    - "istio-system/*"

Example 2: Declare a Sidecar configuration in the prod-us1 namespace to overwrite the global default configuration

The following example declares a Sidecar configuration in the prod-us1 namespace. This configuration overwrites the global default configuration defined in Example 1 and configures the Sidecars in its namespace to allow egress traffic to services in the prod-us1, prod-apis, and istio-system namespaces.

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: default
  namespace: prod-us1
spec:
  egress:
  - hosts:
    - "prod-us1/*"
    - "prod-apis/*"
    - "istio-system/*"

Example 3: Declare a Sidecar configuration for all pods with the label app: ratings

The following example declares a Sidecar configuration in the prod-us1 namespace for all pods with the label app: ratings. These pods belong to the ratings.prod-us1 service. The workload accepts inbound HTTP traffic on port 9080 and forwards it to the workload instance listening on a Unix domain socket. For egress traffic, in addition to the istio-system namespace, the Sidecar proxy only forwards HTTP traffic destined for port 9080 in the prod-us1 namespace.

Expand to view the Sidecar YAML

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: ratings
  namespace: prod-us1
spec:
  workloadSelector:
    labels:
      app: ratings
  ingress:
  - port:
      number: 9080
      protocol: HTTP
      name: somename
    defaultEndpoint: unix:///var/run/someuds.sock
  egress:
  - port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    hosts:
    - "prod-us1/*"
  - hosts:
    - "istio-system/*"

Example 4: Declare a Sidecar configuration for all pods of the productpage.prod-us1 service that have the app:productpage label

If a workload is deployed without IPTables-based traffic capture, the only way to configure the ports of the workload proxy is through a Sidecar configuration.

The following example declares a Sidecar configuration for all pods of the productpage.prod-us1 service that have the app:productpage label in the prod-us1 namespace. Assume that these pods do not use IPTables rules (that is, they lack an istio-init container) and the proxy metadata ISTIO_META_INTERCEPTION_MODE is set to NONE. This configuration allows the pods to receive HTTP traffic on port 9080 (wrapped in Istio bidirectional TLS) and forward it to the application listening on 127.0.0.1:8080. It also enables the application to communicate with a backend MySQL database at 127.0.0.1:3306, which is then proxied to an external MySQL service hosted at mysql.foo.com:3306.

Expand to view the Sidecar YAML

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: no-ip-tables
  namespace: prod-us1
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - port:
      number: 9080 # binds to proxy_instance_ip:9080 (0.0.0.0:9080, if no unicast IP is available for the instance)
      protocol: HTTP
      name: somename
    defaultEndpoint: 127.0.0.1:8080
    captureMode: NONE # not needed if metadata is set for entire proxy
  egress:
  - port:
      number: 3306
      protocol: MYSQL
      name: egressmysql
    captureMode: NONE # not needed if metadata is set for entire proxy
    bind: 127.0.0.1
    hosts:
    - "*/mysql.foo.com"

Expand to view the ServiceEntry YAML

This YAML is used for routing to mysql.foo.com:3306.

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: external-svc-mysql
  namespace: ns1
spec:
  hosts:
  - mysql.foo.com
  ports:
  - number: 3306
    name: mysql
    protocol: MYSQL
  location: MESH_EXTERNAL
  resolution: DNS

Field descriptions

Sidecar

A Sidecar describes the configuration of the Sidecar proxy attached to a workload. The proxy modulates inbound and outbound communications for the workload.

Field

Type

Required

Description

workloadSelector

WorkloadSelector

No

Criteria used to select the pods to which this Sidecar configuration applies. If omitted, the Sidecar configuration applies to all workload instances in the same namespace.

ingress

IstioIngressListener[]

No

Configuration for the proxy to handle inbound traffic for its associated workload.

  • If omitted, the service mesh automatically configures the Sidecar based on information about the workload obtained from the orchestration platform, such as exposed ports and services.

  • If specified, inbound ports are configured only when the workload instance is associated with a service.

egress

IstioEgressListener[]

No

Configuration for the proxy to handle outbound traffic for its associated workload. If not specified, the default Sidecar detected by the system from the namespace or global scope is inherited.

outboundTrafficPolicy

OutboundTrafficPolicy

No

Outbound traffic policy configuration. If your application uses one or more unregistered external services, setting the policy to ALLOW_ANY causes the Sidecar to route any unknown traffic initiated by the application to its requested destination. If not specified, the default Sidecar detected by the system from the namespace or global scope is inherited.

IstioIngressListener

IstioIngressListener specifies the properties of an inbound traffic listener on a Sidecar proxy attached to a workload instance.

Field

Type

Required

Description

port

Port

Yes

The port associated with the listener.

bind

string

No

The IP address (IPv4 or IPv6) to which the listener should bind. Unix domain socket addresses are not allowed in the bind field of an ingress listener. If omitted, the service mesh automatically configures a default value based on the imported services and the workload to which this configuration is applied.

captureMode

CaptureMode

No

Specifies how traffic to the listener is captured, or not captured.

defaultEndpoint

string

Yes

The IP endpoint or Unix domain socket to which traffic should be forwarded. This configuration can be used to redirect traffic arriving at IP:Port on the Sidecar to localhost:Port or a Unix domain socket that the application workload is listening on. Arbitrary IPs are not supported. The format is as follows:

  • 127.0.0.1:PORT

  • [::1]:PORT (forwards to localhost)

  • 0.0.0.0:PORT

  • [::]:PORT (forwards to the instance IP)

  • unix:///path/to/socket (forwards to a Unix domain socket)

tls

ServerTLSSettings

No

A set of TLS-related options. These options enable TLS termination on the Sidecar for requests from outside the mesh. Only SIMPLE and MUTUAL TLS modes are supported.

IstioEgressListener

IstioEgressListener specifies the properties of an outbound traffic listener on a Sidecar proxy attached to a workload instance.

Field

Type

Required

Description

port

Port

No

The port associated with the listener. If a Unix domain socket is used, use 0 as the port number and specify a valid protocol. If a port is specified, it is used as the default destination port for the associated imported hosts. If the port is omitted, Istio infers the listener port based on the imported hosts.

When multiple egress listeners are specified, and some listeners have a specific port while others do not, the hosts exposed on the listener port are based on the listener with the most specific port.

bind

string

No

The IP address (IPv4 or IPv6) to which the listener should bind. If bind is not empty, the port field must be specified. The format is as follows:

  • IPv4 or IPv6 address format

  • unix:///path/to/uds

  • unix://@foobar (Linux abstract namespace).

If omitted, Istio automatically configures a default value based on the imported services, the workload instance to which this configuration is applied, and the captureMode. If captureMode is NONE, bind defaults to 127.0.0.1.

captureMode

CaptureMode

No

When the bind address is an IP, the captureMode option specifies how traffic to the listener is captured, or not captured. For Unix domain socket bindings, captureMode must be DEFAULT or NONE.

hosts

string[]

Yes

The service hosts exposed by the listener, in the format namespace/dnsName. Services that match the dnsName in the specified namespace are exposed. The corresponding service can be a service in the service registry or a service declared using a ServiceEntry or VirtualService. You can also use a DestinationRule that is in the same namespace and associated with this pod.

  • namespace can be set to *, ., or ~, representing any, the current, or no namespace, respectively.

  • dnsName should be specified in FQDN format and can include a wildcard character in the leftmost part (for example, prod/*.example.com). Setting dnsName to * selects all services from the specified namespace (for example, prod/*).

Examples:

  • */foo.example.com selects the service from any available namespace.

  • ./foo.example.com selects the service only from the namespace where the Sidecar is located.

  • If hosts is set to */*, Istio configures the Sidecar to be able to reach every service in the mesh that is exported to the Sidecar's namespace.

  • The value ~/* can be used to configure a Sidecar that only receives and responds to traffic but does not make its own outbound connections.

You can only reference services and configuration files that are exported to the Sidecar's namespace (for example, where the exportTo value is *). Private configurations (for example, where exportTo is set to .) are not available. For more information about the exportTo field, see Virtual Service, Destination Rule, and Service Entry.

WorkloadSelector

WorkloadSelector specifies the conditions under which a Gateway, Sidecar, EnvoyFilter, ServiceEntry, or DestinationRule configuration can be applied to a proxy. Matching conditions include metadata related to the proxy, workload instance information (such as labels attached to a pod), or any other information provided by the proxy to Istio during the initial handshake. If multiple conditions are specified, all conditions must match for a workload instance to be selected. Only label-based selection is supported.

Field

Type

Required

Description

labels

map<string, string>

Yes

One or more labels that indicate a specific set of pods on which the configuration should be applied. The scope of the label search is limited to the namespace where the resource is located.

OutboundTrafficPolicy

OutboundTrafficPolicy sets the default behavior of the Sidecar proxy for handling outbound traffic from an application. If the application uses an unregistered external service, setting the policy to ALLOW_ANY causes the Sidecar to route any unknown traffic from the application to its requested destination. Instead of using ALLOW_ANY, declare external dependencies using a ServiceEntry configuration. This approach enables monitoring of traffic to these services.

Field

Type

Required

Description

mode

string

No

The access policy for external services. The values are described as follows:

  • REGISTRY_ONLY: Outbound traffic is allowed only to services defined in the service registry and services defined through a ServiceEntry configuration.

  • ALLOW_ANY: Outbound traffic to unknown destinations is allowed if there is no service or ServiceEntry configuration for the destination port.

CaptureMode

CaptureMode describes how to capture traffic that is incoming to a listener. This applies only when the listener is bound to an IP address.

Field

Description

DEFAULT

The default capture mode defined by the environment.

IPTABLES

Captures traffic using IPtables redirection.

NONE

Does not capture traffic. When used in an egress listener, the application must explicitly communicate with the listener port or Unix domain socket. When used in an ingress listener, ensure that no other process on the host is using the listener port.