我们部署服务的一个新版本。
取决于sidecar容器的注入类型,在配置阶段添加istio-init容器和istio-agent容器(Envoy),或者手动插入到Kubernetes实体的Pod描述里。
istio-init容器是一些脚本,为Pod设置iptables规则。有两种方式配置流量重定向到istio-agent容器里:使用直接的iptables规则或者TPROXY[2]。撰写本文时,默认使用的是重定向规则。在istio-init里,可以配置截获哪些流量并发送给istio-agent。比如,为了截获所有入站和出站流量,用户需要将参数 -i和 -b设置为 *。用户也可以指定截获特定端口的流量。为了避免截获特定子网的流量,可以使用 -x参数。
在init运行后,会启动容器,包括pilot-agent(Envoy)。它通过GRPC连接上已经部署的Pilot,得到集群内所有已有服务以及路由策略的信息。根据接收到的数据,它配置集群,将这些流量直接映射到Kubernetes集群里的应用程序端口。重要的地方是:Envoy动态配置监听器(IP,端口对)开始监听。因此,当请求进入Pod,并且使用iptables规则重定向到sidecar时,Envoy已经准备好处理这些连接,并且知道将这些代理流量转发到哪里去。这一步里,信息发送给Mixer,下文会详细介绍。
服务1发送请求给服务2
在已有的服务1里,请求重定向到sidecar
Sidecar Envoy监控到给服务2的请求,并准备所需信息
然后它使用Report请求发送给istio-telemetry。
Istio-telemetry决定是否将Report发送给后台,这里也负责发送请求以及请求内容。
apiVersion: v1
kind: ConfigMap
metadata:
name: istio
namespace: istio-system
labels:
app: istio
service: istio
data:
mesh: |-
# disable tracing mechanism for now
enableTracing: false
# do not specify mixer endpoints, so that sidecar containers do not send the information
#mixerCheckServer: istio-policy.istio-system:15004
#mixerReportServer: istio-telemetry.istio-system:15004
# interval for envoy to check Pilot
rdsRefreshDelay: 5s
# default config for envoy sidecar
defaultConfig:
# like rdsRefreshDelay
discoveryRefreshDelay: 5s
# path to envoy executable
configPath: "/etc/istio/proxy"
binaryPath: "/usr/local/bin/envoy"
# default name for sidecar container
serviceCluster: istio-proxy
# time for envoy to wait before it shuts down all existing connections
drainDuration: 45s
parentShutdownDuration: 1m0s
# by default, REDIRECT rule for iptables is used. TPROXY can be used as well.
#interceptionMode: REDIRECT
# port for sidecar container admin panel
proxyAdminPort: 15000
# address for sending traces using zipkin protocol (not used as turned off in enableTracing option)
zipkinAddress: tracing-collector.tracing:9411
# statsd address for envoy containers metrics
# statsdUdpAddress: aggregator:8126
# turn off Mutual TLS
controlPlaneAuthPolicy: NONE
# istio-pilot listen port to report service discovery information to sidecars
discoveryAddress: istio-pilot.istio-system:15007
initContainers:
- name: istio-init
args:
- -p
- "15001"
- -u
- "1337"
- -m
- REDIRECT
- -i
- '*'
- -b
- '*'
- -d
- ""
image: istio/proxy_init:1.0.0
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 128Mi
securityContext:
capabilities:
add:
- NET_ADMIN
- name: istio-proxy
command:
- "bash"
- "-c"
- |
exec /usr/local/bin/pilot-agent proxy sidecar \
--configPath \
/etc/istio/proxy \
--binaryPath \
/usr/local/bin/envoy \
--serviceCluster \
service-name \
--drainDuration \
45s \
--parentShutdownDuration \
1m0s \
--discoveryAddress \
istio-pilot.istio-system:15007 \
--discoveryRefreshDelay \
1s \
--connectTimeout \
10s \
--proxyAdminPort \
"15000" \
--controlPlaneAuthPolicy \
NONE
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: INSTANCE_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ISTIO_META_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ISTIO_META_INTERCEPTION_MODE
value: REDIRECT
image: istio/proxyv2:1.0.0
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
memory: 2048Mi
securityContext:
privileged: false
readOnlyRootFilesystem: true
runAsUser: 1337
volumeMounts:
- mountPath: /etc/istio/proxy
name: istio-envoy
CIDR Pod和Service CIDR必须在所有集群里都是唯一的,不能重叠。
集群间的任意Pod CIDR必须能够访问所有CIDR Pod。
所有Kubernetes API server都必须能够相互访问。
https://istio.io/docs/concepts/
https://www.envoyproxy.io/
https://github.com/kristrev/tproxy-example/blob/master/tproxy_example.c
https://istio.io/docs/concepts/policies-and-telemetry/overview/
https://github.com/istio/istio/blob/release-1.0/install/kubernetes/helm/istio/charts/pilot/templates/deployment.yaml
https://github.com/istio/istio/tree/release-1.0/install/kubernetes/helm/istio/charts/pilot/templates
https://istio.io/docs/setup/kubernetes/multicluster-install/