工作负载条目
WorkloadEntry
使操作员能够描述单个非 Kubernetes 工作负载(例如虚拟机或裸机服务器)在加入网格时的属性。WorkloadEntry
必须与 Istio ServiceEntry
结合使用,该条目通过相应的标签选择工作负载,并为MESH_INTERNAL
服务(主机名、端口属性等)提供服务定义。ServiceEntry
对象可以选择多个工作负载条目以及基于服务条目中指定的标签选择器的 Kubernetes Pod。
当工作负载连接到istiod
时,自定义资源中的状态字段将更新以指示工作负载的健康状况以及其他详细信息,类似于 Kubernetes 如何更新 Pod 的状态。
以下示例声明了一个工作负载条目,该条目表示details.bookinfo.com
服务的虚拟机。此虚拟机已安装 sidecar 并使用details-legacy
服务帐户引导。该服务在端口 80 上向网格中的应用程序公开。到此服务的 HTTP 流量包装在 Istio 双向 TLS 中,并发送到目标端口 8080 上虚拟机上的 sidecar,然后 sidecar 将其转发到同一端口上的 localhost 上的应用程序。
apiVersion: networking.istio.io/v1
kind: WorkloadEntry
metadata:
name: details-svc
spec:
# use of the service account indicates that the workload has a
# sidecar proxy bootstrapped with this service account. Pods with
# sidecars will automatically communicate with the workload using
# istio mutual TLS.
serviceAccount: details-legacy
address: 2.2.2.2
labels:
app: details-legacy
instance-id: vm1
以及关联的服务条目
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
name: details-svc
spec:
hosts:
- details.bookinfo.com
location: MESH_INTERNAL
ports:
- number: 80
name: http
protocol: HTTP
targetPort: 8080
resolution: STATIC
workloadSelector:
labels:
app: details-legacy
以下示例使用其完全限定的 DNS 名称声明相同的 VM 工作负载。服务条目的解析模式应更改为 DNS,以指示客户端 sidecar 应在转发请求之前在运行时动态解析 DNS 名称。
apiVersion: networking.istio.io/v1
kind: WorkloadEntry
metadata:
name: details-svc
spec:
# use of the service account indicates that the workload has a
# sidecar proxy bootstrapped with this service account. Pods with
# sidecars will automatically communicate with the workload using
# istio mutual TLS.
serviceAccount: details-legacy
address: vm1.vpc01.corp.net
labels:
app: details-legacy
instance-id: vm1
以及关联的服务条目
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
name: details-svc
spec:
hosts:
- details.bookinfo.com
location: MESH_INTERNAL
ports:
- number: 80
name: http
protocol: HTTP
targetPort: 8080
resolution: DNS
workloadSelector:
labels:
app: details-legacy
以下示例声明了一个没有地址的 VM 工作负载。除了让 istiod 从远程 API 服务器读取之外,还可以编写本地集群中的WorkloadEntry
,该条目表示远程网络中具有给定标签的工作负载。单个带有权重的WorkloadEntry
表示给定远程网络中所有实际工作负载的聚合。
apiVersion: networking.istio.io/v1
kind: WorkloadEntry
metadata:
name: foo-workloads-cluster-2
spec:
serviceAccount: foo
network: cluster-2-network
labels:
app: foo
WorkloadEntry
WorkloadEntry 允许指定单个非 Kubernetes 工作负载(例如 VM 或裸机服务)的属性,服务条目可以引用这些属性。