apiVersion: apps/v1
kind: Deployment
metadata:
name: helloserver
spec:
replicas: 1
selector:
matchLabels:
app: helloserver
template:
metadata:
labels:
app: helloserver
spec:
containers:
- image: gcr.io/google-samples/istio/helloserver:v0.0.1
imagePullPolicy: Always
name: main
restartPolicy: Always
terminationGracePeriodSeconds: 5
kind 表示对象的类型。
metadata.name 指定 Deployment 的名称。
第一个 spec 字段包含所需状态的说明。
spec.replicas 指定所需 Pod 的数量。
spec.template 部分定义 Pod 模板。Pod 的规范中包含 image 字段,该字段是从 Container Registry 中拉取的映像的名称。
Service 的定义如下:
apiVersion: v1
kind: Service
metadata:
name: hellosvc
spec:
ports:
- name: http
port: 80
targetPort: 8080
selector:
app: helloserver
type: LoadBalancer
targetPort:回想一下,Dockerfile 中的 EXPOSE 8080 命令不会实际公开任何端口。您可以公开端口 8080,以便访问集群外部的 server 容器。在这种情况下,hellosvc.default.cluster.local:80(简称:hellosvc)映射到 helloserver Pod IP 的端口 8080。
port:这是在发送请求时集群中的其他服务使用的端口号。
网关
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: servicemesh-cloud-gw
namespace: istio-ingress
labels:
istio-injection: enabled
spec:
gatewayClassName: asm-l7-gxlb
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All