sidecar详解

【架构师之路】微服务架构设计中的边车(Sidecar)模式 Sidecar模式是一种架构设计模式,通常用于微服务架构中。它通过将辅助功能与主应用程序分离,使得主服务可以专注于其核心业务逻辑。Sidecar模式指的是在微服务架构中,将一些常见的功能(如日志记录、监控、服务发现等)封装在一个独立的服务或代理中(例如 Kubernetes 中的 Pod),这个服务与主服务并行运行,形成“侧车”结构。如下图所示,sidecar 模式允许您在应用程序旁边添加更多功能,而无需额外第三方组件配置或修改应用程序代码。 阅读详情

 欢迎关注我的公众号:

 目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:

istio多集群探秘,部署了50次多集群后我得出的结论

istio多集群链路追踪,附实操视频

istio防故障利器,你知道几个,istio新手不要读,太难!

istio业务权限控制,原来可以这么玩

istio实现非侵入压缩,微服务之间如何实现压缩

不懂envoyfilter也敢说精通istio系列-http-rbac-不要只会用AuthorizationPolicy配置权限

不懂envoyfilter也敢说精通istio系列-02-http-corsFilter-不要只会vs

不懂envoyfilter也敢说精通istio系列-03-http-csrf filter-再也不用再代码里写csrf逻辑了

不懂envoyfilter也敢说精通istio系列http-jwt_authn-不要只会RequestAuthorization

不懂envoyfilter也敢说精通istio系列-05-fault-filter-故障注入不止是vs

不懂envoyfilter也敢说精通istio系列-06-http-match-配置路由不只是vs

不懂envoyfilter也敢说精通istio系列-07-负载均衡配置不止是dr

不懂envoyfilter也敢说精通istio系列-08-连接池和断路器

不懂envoyfilter也敢说精通istio系列-09-http-route filter

不懂envoyfilter也敢说精通istio系列-network filter-redis proxy

不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager

不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册

学习目标

什么是sidecar

Sidecar描述了sidecar代理的配置,sidecar代理调解与其连接的工作负载的 inbound 和 outbound 通信。 默认情况下,Istio将为网格中的所有Sidecar代理服务,使其具有到达网格中每个工作负载所需的必要配置,并在与工作负载关联的所有端口上接收流量。 Sidecar资源提供了一种的方法,在向工作负载转发流量或从工作负载转发流量时,微调端口集合和代理将接收的协议。 此外,可以限制代理在从工作负载转发 outbound 流量时可以达到的服务集合。

网格中的服务和配置被组织成一个或多个名称空间(例如,Kubernetes名称空间或CF org/space)。 命名空间中的Sidecar资源将应用于同一命名空间中的一个或多个工作负载,由workloadSelector选择。 如果没有workloadSelector,它将应用于同一名称空间中的所有工作负载。 在确定要应用于工作负载的Sidecar资源时,将优先使用通过workloadSelector而选择到此工作负载的的资源,而不是没有任何workloadSelector的资源。

注意:每个命名空间只能有一个没有任何工作负载选择器的Sidecar资源。 如果给定命名空间中存在多个无选择器的Sidecar资源,则系统的行为是不确定的。 如果具有工作负载选择器的两个或多个Sidecar资源选择相同的工作负载,则系统的行为是不确定的。

资源详解

FieldTypeDescriptionRequired
workloadSelectorWorkloadSelectorCriteria used to select the specific set of pods/VMs on which this Sidecar configuration should be applied. If omitted, the Sidecar configuration will be applied to all workload instances in the same namespace.No
ingressIstioIngressListener[]Ingress specifies the configuration of the sidecar for processing inbound traffic to the attached workload instance. If omitted, Istio will automatically configure the sidecar based on the information about the workload obtained from the orchestration platform (e.g., exposed ports, services, etc.). If specified, inbound ports are configured if and only if the workload instance is associated with a service.No
egressIstioEgressListener[]Egress specifies the configuration of the sidecar for processing outbound traffic from the attached workload instance to other services in the mesh.Yes
outboundTrafficPolicyOutboundTrafficPolicyThis allows to configure the outbound traffic policy. If your application uses one or more external services that are not known apriori, setting the policy to ALLOW_ANY will cause the sidecars to route any unknown traffic originating from the application to its requested destination.No

全局有效

sc-default-global.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: default
  namespace: istio-system
spec:
  ingress:
  - port:
      number: 9080
      protocol: HTTP
      name: http
    defaultEndpoint: 127.0.0.1:9080

workloadSelector

没有selector

sc-default-istio-ingress.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: default
spec:
  ingress:
  - port:
      number: 9080
      protocol: HTTP
      name: http
    defaultEndpoint: 127.0.0.1:9080

有selector

sc-productpage-selector.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - port:
      number: 9081
      protocol: HTTP
      name: http
    defaultEndpoint: 127.0.0.1:9080

监听端口和目标端口不一致,可用于端口转换

此时service需要添加端口

kubectl edit svc productpage -n istio

  - name: http9081
    port: 9081
    protocol: TCP
    targetPort: 9081

修改vs端口

sidecar/vs-bookinfo-hosts-star.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage.istio.svc.cluster.local
        port:
          number: 9081

egress

FieldTypeDescriptionRequired
portPortThe port associated with the listener. If using Unix domain socket, use 0 as the port number, with a valid protocol. The port if specified, will be used as the default destination port associated with the imported hosts. If the port is omitted, Istio will infer the listener ports based on the imported hosts. Note that when multiple egress listeners are specified, where one or more listeners have specific ports while others have no port, the hosts exposed on a listener port will be based on the listener with the most specific port.No
bindstringThe IP or the Unix domain socket to which the listener should be bound to. Port MUST be specified if bind is not empty. Format: x.x.x.x or unix:///path/to/uds or unix://@foobar (Linux abstract namespace). If omitted, Istio will automatically configure the defaults based on imported services, the workload instances to which this configuration is applied to and the captureMode. If captureMode is NONE, bind will default to 127.0.0.1.No
captureModeCaptureModeWhen the bind address is an IP, the captureMode option dictates how traffic to the listener is expected to be captured (or not). captureMode must be DEFAULT or NONE for Unix domain socket binds.No
hostsstring[]One or more service hosts exposed by the listener in namespace/dnsName format. Services in the specified namespace matching dnsName will be exposed. The corresponding service can be a service in the service registry (e.g., a Kubernetes or cloud foundry service) or a service specified using a ServiceEntry or VirtualService configuration. Any associated DestinationRule in the same namespace will also be used.The dnsName should be specified using FQDN format, optionally including a wildcard character in the left-most component (e.g., prod/*.example.com). Set the dnsName to * to select all services from the specified namespace (e.g., prod/*).The namespace can be set to *, ., or ~, representing any, the current, or no namespace, respectively. For example, */foo.example.com selects the service from any available namespace while ./foo.example.com only selects the service from the namespace of the sidecar. If a host is set to */*, Istio will configure 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 completely trim the configuration for sidecars that simply receive traffic and respond, but make no outbound connections of their own.NOTE: Only services and configuration artifacts exported to the sidecar’s namespace (e.g., exportTo value of *) can be referenced. Private configurations (e.g., exportTo set to .) will not be available. Refer to the exportTo setting in VirtualService, DestinationRule, and ServiceEntry configurations for details.WARNING: The list of egress hosts in a Sidecar must also include the Mixer control plane services if they are enabled. Envoy will not be able to reach them otherwise. For example, add host istio-system/istio-telemetry.istio-system.svc.cluster.local if telemetry is enabled, istio-system/istio-policy.istio-system.svc.cluster.local if policy is enabled, or add istio-system/* to allow all services in the istio-system namespace. This requirement is temporary and will be removed in a future Istio release.Yes

port

sc-productpage-egress-port.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp

bind

0.0.0.0

sc-productpage-egress-bind.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 0.0.0.0

目标svc ip

sc-productpage-egress-bind-svc-ip.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 10.68.190.94

captureMode

NameDescription
DEFAULTThe default capture mode defined by the environment.
IPTABLESCapture traffic using IPtables redirection.
NONENo traffic capture. When used in an egress listener, the application is expected to explicitly communicate with the listener port or Unix domain socket. When used in an ingress listener, care needs to be taken to ensure that the listener port is not in use by other processes on the host.

DEFAULT

sc-productpage-egress-captureMode-DEFAULT.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 0.0.0.0
    captureMode: DEFAULT

IPTABLES

sc-productpage-egress-captureMode-IPTABLES.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 0.0.0.0
    captureMode: IPTABLES

NONE

sc-productpage-egress-captureMode-NONE.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 0.0.0.0
    captureMode: NONE

sc-productpage-ingress-captureMode-NONE.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 127.0.0.1
    captureMode: NONE

进入和出去流量都不捕获,相当于去掉了sidecar,对这个pod的istio资源将不起作用。

注意mesh配置,允许集群外访问

outboundTrafficPolicy: mode: REGISTRY_ONLY| ALLOW_ANY

hosts

dot

sc-productpage-egress-hosts-dot.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "./*"

semi-star

sc-productpage-egress-hosts-semi-star.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "istio/*"

double-star

sc-productpage-egress-hosts-double-star.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "*/*"

specific

sc-productpage-egress-hosts-specific.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  egress:
  - hosts:
    - "istio/details.istio.svc.cluster.local"

ingress

FieldTypeDescriptionRequired
portPortThe port associated with the listener.Yes
bindstringThe IP to which the listener should be bound. Must be in the format x.x.x.x. Unix domain socket addresses are not allowed in the bind field for ingress listeners. If omitted, Istio will automatically configure the defaults based on imported services and the workload instances to which this configuration is applied to.No
captureModeCaptureModeThe captureMode option dictates how traffic to the listener is expected to be captured (or not).No
defaultEndpointstringThe loopback IP endpoint or Unix domain socket to which traffic should be forwarded to. This configuration can be used to redirect traffic arriving at the bind IP:Port on the sidecar to a localhost:port or Unix domain socket where the application workload instance is listening for connections. Format should be 127.0.0.1:PORT or unix:///path/to/socketYes

port

sc-productpage-ingress-port.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: IPTABLES
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

bind

sc-productpage-ingress-bind.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: IPTABLES
    bind: 0.0.0.0
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

sc-productpage-ingress-bind-pod-ip.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: IPTABLES
    bind: 172.20.1.174
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

bind pod ip

captureMode

NameDescription
DEFAULTThe default capture mode defined by the environment.
IPTABLESCapture traffic using IPtables redirection.
NONENo traffic capture. When used in an egress listener, the application is expected to explicitly communicate with the listener port or Unix domain socket. When used in an ingress listener, care needs to be taken to ensure that the listener port is not in use by other processes on the host.

DEFAULT

sc-productpage-ingress-capture-mode-DEFAULT.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: DEFAULT
    bind: 0.0.0.0
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

IPTABLES

sc-productpage-ingress-capture-mode-IPTABLES.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: IPTABLES
    bind: 0.0.0.0
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

NONE

sc-productpage-ingress-capture-mode-NONE.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

defaultEndpoint

unix socket

1部署mysqlgateway

kubectl apply -f gateway/gateway-mysql.yaml -n istio

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: mysql
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 3306
      name: mysql
      protocol: MYSQL
    hosts:
    - "*"

2部署mysql vs

kubectl apply -f gateway/protocol/vs-mysql.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: mysql
spec:
  hosts:
  - "*"
  gateways:
  - mysql
  tcp:
  - match:
    - port: 3306
    route:
    - destination:
        host: mysqldb.istio.svc.cluster.local
        port:
          number: 3306

3添加svc 端口

kubectl edit svc istio-ingressgateway -n istio-system

3306端口

4部署sidecar

sc-mysql-defaultEndpoint-unix.yaml

当绑定地址是IP时,captureMode选项指示如何劫持(或不劫持)到监听器的流量。 对于Unix domain socket,captureMode必须为DEFAULT或NONE。

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: mysql
spec:
  workloadSelector:
    labels:
      app: mysqldb
  ingress:
  - bind: 0.0.0.0
    port:
      number: 3306
      protocol: MYSQL
      name: mysql
    defaultEndpoint: unix:///var/run/mysqld/mysqld.sock
    captureMode: NONE

ip -port

sc-productpage-ingerss-defaultEndpoint-ip.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http

outboundTrafficPolicy

egressProxy

egressProxyDestinationSpecifies the details of the egress proxy to which unknown traffic should be forwarded to from the sidecar. Valid only if the mode is set to ALLOW_ANY. If not specified when the mode is ALLOW_ANY, the sidecar will send the unknown traffic directly to the IP requested by the application. ** NOTE 1: The specified egress host must be imported in the egress section for the traffic forwarding to work. NOTE 2**: An Envoy based egress gateway is unlikely to be able to handle plain text TCP connections forwarded from the sidecar. Envoy's dynamic forward proxy can handle only HTTP and TLS connections. $hide_from_docs
FIELDTYPELABELDESCRIPTION
hoststringThe name of a service from the service registry. Service names are looked up from the platform's service registry (e.g., Kubernetes services, Consul services, etc.) and from the hosts declared by ServiceEntry. Traffic forwarded to destinations that are not found in either of the two, will be dropped. Note for Kubernetes users: When short names are used (e.g. “reviews” instead of “reviews.default.svc.cluster.local”), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the “default” namespace containing a host “reviews will be interpreted as “reviews.default.svc.cluster.local”, irrespective of the actual namespace associated with the reviews service. To avoid potential misconfiguration, it is recommended to always use fully qualified domain names over short names.
subsetstringThe name of a subset within the service. Applicable only to services within the mesh. The subset must be defined in a corresponding DestinationRule.
portPortSelectorSpecifies the port on the host that is being addressed. If a service exposes only a single port it is not required to explicitly select the port

host

sc-productpage-outboundTrafficPolicy-egressProxy-host.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  outboundTrafficPolicy:
    egressProxy:
      host: "details.istio.svc.cluster.local"
      port:
        number: 9080
    mode: ALLOW_ANY

port

sc-productpage-outboundTrafficPolicy-egressProxy-port.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  outboundTrafficPolicy:
    egressProxy:
      host: "details.istio.svc.cluster.local"
      port:
        number: 9080
    mode: ALLOW_ANY

subset

sc-productpage-outboundTrafficPolicy-egressProxy-subset.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  outboundTrafficPolicy:
    egressProxy:
      host: "details.istio.svc.cluster.local"
      port:
        number: 9080
      subset: v1
    mode: ALLOW_ANY

mode

NameDescription
REGISTRY_ONLYOutbound traffic will be restricted to services defined in the service registry as well as those defined through ServiceEntry configurations.
ALLOW_ANYOutbound traffic to unknown destinations will be allowed, in case there are no services or ServiceEntry configurations for the destination port.

REGISTRY_ONLY

sc-productpage-outboundTrafficPolicy-mode-REGISTRY_ONLY.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  outboundTrafficPolicy:
    mode: REGISTRY_ONLY

ALLOW_ANY

sc-productpage-outboundTrafficPolicy-mode-ALLOW_ANY.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  outboundTrafficPolicy:
    mode: ALLOW_ANY

组合应用

sc-productpage-complex.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 127.0.0.1
    captureMode: NONE
  outboundTrafficPolicy:
    mode: REGISTRY_ONLY

outbound将不能访问

sc-productpage-complex-02.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 127.0.0.1
    captureMode: NONE
  outboundTrafficPolicy:
    mode: ALLOW_ANY

可以访问outbound

sc-productpage-complex-03.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: productpage
spec:
  workloadSelector:
    labels:
      app: productpage
  ingress:
  - captureMode: NONE
    defaultEndpoint: 127.0.0.1:9080
    port:
      number: 9080
      protocol: HTTP
      name: http
  egress:
  - hosts:
    - "./*"
    port:
      number: 9080
      protocol: HTTP
      name: egresshttp
    bind: 127.0.0.1
    captureMode: NONE
  outboundTrafficPolicy:
    mode: ALLOW_ANY
    egressProxy:
      host: "details.istio.svc.cluster.local"
      port:
        number: 9080
      subset: v1

只有detail outbound能访问

egress_proxy must be set only with ALLOW_ANY outbound_traffic_policy mode

使用ServiceEntry

1进入pod访问www.baidu.com

kubectl exec -it sleep-557747455f-ft9bs -n istio -- /bin/sh

curl www.baidu.com

可以访问

2部署sidecar

sc-sleep-REGISTRY_ONLY.yaml

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
  name: sleep
spec:
  workloadSelector:
    labels:
      app: sleep
  outboundTrafficPolicy:
    mode: REGISTRY_ONLY

3在访问www.baidu.com

不能访问

4部署serviceentry

serviceentries/se-baidu.yaml

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: baidu
spec:
  hosts:
  - "www.baidu.com"
  ports:
  - number: 80
    name: http
    protocol: HTTP
  location: MESH_EXTERNAL
  resolution: DNS

5再访问www.baidu.com

可以访问

深入剖析 Kubernetes 原生 Sidecar 容器 Kubernetes 1.28 引入了一种新型容器 - sidecar 容器。Kubernetes 将 sidecar 容器作为 init 容器的一个特例来实现,在 Pod 启动后,sidecar 容器仍将保持运行状态。具体的实现方式是在 init 容器中添加了一个新的字段, 该字段在特性门控启用时可用(该特性自 Kubernetes v1.29 起默认启用)。该字段是可选的,如果对其设置,则唯一有效的值为Always。 阅读详情

相关推荐

【云原生技术】云原生中的sidecar

在云原生架构中,Sidecar 是一种设计模式,指的是将辅助功能(如监控、日志、安全等)作为独立的容器部署在同一 Pod 中,与主应用程序容器共享同一生命周期和资源。这种模式使得辅助功能与主应用程序能够紧密协作,而不需要修改主应用程序的代码。在云原生架构中,Sidecar 提供了一种灵活和有效的方式来扩展和增强主应用程序的功能,同时保持应用程序的简洁性和独立性。数据在应用与应用之间的传递和交换则依赖于网络通信、消息队列、共享存储等多种方式,确保应用在分布式和微服务架构中能够高效地协作和交互。

weixin_46453070的博客 1992

微服务边车模式深度解析:赋能云原生应用的终极指南(自己搞一个简单SideCar?)

通过使用Sidecar模式,我们能够实现对微服务架构的强化,也就是关注点分离,让你专注于开车,开好车,开快车。它提供了一种有效的方式去分摊微服务的辅助功能(如日志记录、监控、配置管理、网络通信等),而无需改动微服务的核心业务逻辑。这带来了显著的优点,包括简化开发复杂度、增强服务的可维护性和可伸缩性,以及提供了横切关注点(cross-cutting concerns)的统一管理。

fofcn的专栏 4991

39、Istio 安装定制与 Sidecar 注入详解

本文详细介绍了 Istio 的安装定制与 Sidecar 注入的实现方法,包括使用 Helm、istioctl、istio-operator 等多种安装方式,以及手动和自动注入 Sidecar 的操作流程。文章还对比了不同安装和注入方式的优缺点,并提供了常见问题的解决方法,帮助用户更好地理解和掌握 Istio 的使用。

milk5的博客 163

Sidecar 模式的机制与应用

什么是 Sidecar 模式 将应用程序的功能划分为单独的进程,即 Sidecar 模式。Sidecar 译为摩托车的边车,用到软件架构中,Sidecar 模式指在原来的业务逻辑上再新加一个抽象层。 Sidecar 模式是一种更具动态性的方法,其作为一种模式并不是 Kubernetes 的正式约定。它将应用程序的功能划分为单独的进程,运行在同一个 pod 中,Sidecar 模式允许在应用程序旁边添加功能,而无需修改应用程序代码。 Sidecar 示意图 Sidecar 的优势 在 Sidecar 部署方

quanxiangcloud的博客 3774

15、Kubernetes 容器模式:Init Container 与 Sidecar 详解

本文详细介绍了 Kubernetes 中两种重要的容器模式:Init Container 和 Sidecar。通过分离初始化任务和增强主应用容器功能,这两种模式分别提升了应用的可靠性、灵活性和可维护性,并结合实际场景探讨了它们的应用价值。

docker8compose的博客 222

39、Istio 安装定制与 Sidecar 注入选项详解

本文详细解析了 Istio 的安装定制与 Sidecar 注入选项。首先介绍了 Istio 的多种安装方式,包括 helm、istioctl、istio-operator 和 kubectl,分析了各自的优缺点及适用场景;接着深入探讨了 Sidecar 的组成及其手动和自动注入方式,并通过流程图展示了工作原理;最后对比了不同安装和注入方式,总结了实际应用中的注意事项,并给出了决策流程图以帮助用户选择合适的方案。

c8d9e0f1的博客 121

Kubernetes Sidecar容器模式详解与应用实践

Sidecar容器是云原生架构中重要的设计模式,通过将辅助功能与主业务容器解耦来实现模块化部署。其核心原理是利用Kubernetes Pod的共享命名空间特性,使Sidecar容器能访问主容器的网络、存储等资源。这种模式在服务网格、日志收集等场景展现巨大技术价值,既能保持主容器的轻量化,又能复用Istio、Fluentd等标准化组件。典型应用包括通过Envoy实现流量管理、使用Fluentd进行日志采集等工程实践。随着eBPF等新技术发展,Sidecar模式正向着更轻量化、高性能方向演进。

weixin_34110749的博客 336

【Kubernetes】Kubernetes Sidecar 容器详解:从入门到精通

Kubernetes Sidecar 容器是运行在主应用容器同一Pod中的辅助容器,用于扩展主应用功能(如日志采集、监控等)。本文详细介绍了Sidecar的工作原理、实现方式和生命周期管理,包含两个典型示例:Web应用日志采集和Job任务监控。关键点包括:通过initContainers+restartPolicy实现Sidecar、共享存储卷机制、以及容器启动/停止的顺序逻辑。文章还对比了不同Kubernetes版本对Sidecar的支持情况,适合有一定K8s基础的技术人员深入理解Sidecar模式。

九师兄 70

终极指南:Kubernetes Sidecar注入实战与Mutating Admission Webhook详解

Kubernetes Sidecar注入是现代容器编排中的关键技术,而kube-sidecar-injector作为一款强大的Kubernetes Mutating Admission Webhook服务器,能够在Pod持久化之前自动注入Sidecar容器,极大简化了服务网格、日志收集等场景的部署流程。本文将带你从基础到实战,全面掌握这一技术的核心原理与应用方法。 ## 什么是Kubernete

gitblog_00079的博客 500

AI应用开发利器:Sidecar模式详解与codestoryai/sidecar实战部署

在微服务架构中,Sidecar(边车)模式是一种经典的辅助服务设计模式,它通过将通用功能(如日志、监控、安全)从主业务逻辑中解耦,以独立进程的形式与主应用协同运行。其核心原理是为每个服务实例附加一个伴生容器,负责处理横切关注点,从而提升系统的模块化、可维护性和语言无关性。这一模式的技术价值在于实现了业务逻辑与基础设施的清晰分离,允许团队独立升级和扩展辅助功能,同时增强了应用的安全性和可观测性。在云原生和AI应用开发领域,Sidecar模式被广泛应用于API网关、服务网格(如Istio)、以及管理外部服务调用

weixin_42557537的博客 523

STGCN实战:从零构建PyTorch时空图卷积网络预测城市交通流

本文详细介绍了如何使用PyTorch从零构建时空图卷积网络(STGCN)进行城市交通流预测。通过将交通网络建模为图结构,并融合时间卷积与空间图卷积,STGCN能有效捕捉交通流的时空依赖性。文章提供了从数据预处理、核心模块(TimeBlock与STGCNBlock)搭建、模型训练到实战技巧的完整指南,帮助开发者快速掌握这一前沿的交通速度预测技术。

wasm7browser的博客 252

OpenTelemetry Collector 无侵入式部署:Sidecar模式详解

你是否正面临以下困境?微服务架构下分布式追踪部署复杂,代码侵入性改造风险高,多语言服务监控配置碎片化。OpenTelemetry Collector的Sidecar模式提供了革命性解决方案——无需修改业务代码,通过容器编排实现全链路数据采集,同时保持配置统一与服务隔离。本文将系统拆解Sidecar部署的实施路径,包含架构设计、资源配置、性能调优全流程,助你30分钟内完成生产级监控接入。 读完本文...

gitblog_00733的博客 1214

微信支付开发之平台给用户转账到零钱的功能

请求消息中应包含商家批次单号、转账名称、appid、转账总金额、转账总笔数、转账openid、收款用户姓名等信息。批次已受理成功,若发起批量转账的30分钟后,转账批次单仍处于该状态,可能原因是商户账户余额不足等。【转账场景ID】 该批次转账使用的转账场景,如不填写则使用商家的默认场景,如无默认场景可为空,可前往“商家转账到零钱-前往功能”中申请。【转账总笔数】 一个转账批次单最多发起一千笔转账。【商家批次单号】 商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一。

程序员weixin_sodomany的博客 3461

Sidecar-详解 JuiceFS CSI Driver 新模式

•Pod:可以在 Kubernetes 中创建和管理的、最小的可部署的计算单元•:声明式资源,对 Pod 的不同管理方式•:集群中的一块存储•:表达的是用户对存储的请求•:为管理员提供了描述存储 “类” 的方法•:容器存储接口。

JuiceFS的博客 1017

LAMMPS+Phonopy计算声子色散曲线

机器学习训练完势函数之后,需要对加以验证。对于晶体而言,色散曲线是其衡量计算是否准确的最重要标准,当然,还有能量,比热,RDF等性质。

qq_68842798的博客 3466

Spring Boot Jar包加密实战:用ClassFinal与Jasypt打造代码安全堡垒

Spring Boot代码加密与配置保护方案 针对Spring Boot项目源码和配置易被反编译的风险,本文提出ClassFinal字节码加密+Jasypt配置加密的组合方案。ClassFinal通过Maven插件对核心代码加密,运行时需JavaAgent加载,反编译后仅保留空方法体;Jasypt则采用强加密算法保护敏感配置。方案优势包括: 双重保护:ClassFinal加密业务逻辑,Jasypt加密数据库密码等配置 灵活部署:支持密码启动、机器绑定等安全策略 平滑集成:兼容Spring生态,动态解密结合配

墨夶的博客 1098

HashiCorp Nomad 中的 sidecar_task 配置详解

在现代微服务架构中,服务网格(Service Mesh)已成为确保服务间安全通信的关键技术。HashiCorp Nomad 通过与 Consul Connect 的深度集成,为工作负载提供了强大的服务网格能力。其中,`sidecar_task` 配置块作为 Nomad Connect 功能的核心组件,允许用户精细控制 Envoy 代理 sidecar 容器的行为。 本文将深入解析 `sideca...

gitblog_00264的博客 357

FH8626V100之开发环境搭建

FH8626V100是富瀚微出的一款带摄像头的方案,开发工具在Linux 上进行。版本 Ubuntu 20.04 64位。

xue_nuo的博客 1万+

Istio 中的 Sidecar 注入及透明流量劫持过程详解

图片来源:上海五角场 by Jimmy Song本文基于 Istio 1.5.1 版本,将为大家介绍以下内容:什么是 sidecar 模式和它的优势在哪里。Istio 中是如何做 sid...

dotNET跨平台 1828

3步搞定.NET Core在UOS上的部署?手把手教你从零到上线!

本文详细介绍了如何在统信UOS系统上部署.NET Core应用程序的完整流程。首先,通过安装.NET Core SDK,确保UOS系统能够编译和运行C#代码。接着,创建一个简单的控制台应用,并验证其本地运行情况。最后,通过发布应用、传输文件到UOS服务器,并解决权限问题,确保应用能够在UOS上顺利运行。文章还提供了常见问题的解决方案,如依赖缺失、权限不足和服务启动失败等,帮助开发者避免常见陷阱。通过本文的指导,开发者可以轻松将.NET Core应用部署到UOS系统,并实现24/7的稳定运行。

java专栏 592

【MT7628】固件开发-SDK4320添加MT7612E WiFi驱动操作说明

【MT7628】固件开发-SDK4320添加MT7612E WiFi驱动操作说明

wgl307293845的博客 2084

Istio 1.13 中的 Sidecar CRD 资源详解及案例

默认情况下,Istio 会将整个网格的所有配置推送到每个 Envoy 代理。自定义资源定义(CRD)用于精细控制特定工作负载的 Envoy 代理所看到的服务和配置范围。通过配置 Sidecar,可以减少代理的配置量,提高性能,并增强安全性。在默认情况下,即使未明确配置 Sidecar 资源,工作负载仍然可以访问其他命名空间的服务。然而,在默认情况下,代理可能仍然能够访问其他命名空间的服务,这是由于。,可以精确控制工作负载的服务访问范围,增强集群的安全性和性能。按照此配置,其他命名空间的服务将无法被访问。

华哥技术栈 1288

【YOLOv8改进-损失函数】 YOLOv8自带损失函数CIoU / DIoU / GIoU 详解,以及如何切换损失函数

在介绍YOLOv8中的各种Iou之前,我们先来了解了解目标检测中的损失函数。目标检测模型通常包含两类损失函数:类别损失(分类)和位置损失(回归)。这两类损失函数用于检测模型的最后一部分,根据模型的输出(类别和位置)以及实际标注框(类别和位置),分别计算类别损失和位置损失。

专注于图像领域,主要研究内容包括计算机视觉和深度学习,特别是在图像分类、目标检测和图像生成等方面有深入的研究和实践经验。 5193

Madeira 性能剖析实践:把静默杀进程与掉帧逐一定位到根因的四步法

给 Madeira(在 iPhone 上跑 x86-64 Windows 游戏的 FEX-Emu + Wine + DXMT/Metal 方案)做性能剖析,和普通 iOS 应用最大的不同在于:它是一层套一层的模拟环境,热节流、内存墙、指令翻译开销会互相伪装成"游戏卡"。本文给出一个漏斗式的排查流程——先搭好观测点,再按"进程没了 / 帧率上不去 / 发热掉帧"三种症状逐一定性归因,最后用双日志 A

gitblog_00342的博客 472

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

sidecar异构调用php,spring cloud中利用sidecar整合异构语言(转)详解

用spring cloud sidecar的整合异构语言,以前做过没有做笔记,现在再做由于各种坑又浪费了一天,这里记一下首先是官网:http://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/1.3.1.RELEASE/ 官网上面讲sidecar讲的很简单,具体怎么做这里就不记了,无非就是加包,然后在主函数上面注解,再在配置文件里...

weixin_39631344的博客 282

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

上一篇: authorizationPolicy详解
下一篇: requestAuthentication详解
hxpjava1
博客等级 码龄19年 1365粉丝 511原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址