You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.7 KiB

11 months ago
# 表示使用的是 Kubernetes 的核心 API 版本 1这是最稳定和广泛使用的API版本之一通常用于Service、Pod、Namespace等核心资源。
1 year ago
apiVersion: v1
11 months ago
# Service 是一种核心资源,用于定义微服务架构中的服务访问策略。
1 year ago
kind: Service
11 months ago
# 资源的元数据信息
1 year ago
metadata:
11 months ago
# 组键值对用于标识和选择资源。标签可以用于组织资源、选择资源进行操作以及在Service中定义Pod的选择器。
1 year ago
labels:
11 months ago
# 用来选择和分组具有相同应用名称的资源。
1 year ago
app: gw-charge
name: gw-charge
namespace: yibin-charge
11 months ago
# 服务监听设置
1 year ago
spec:
ports:
- name: http
11 months ago
port: 7001 # 服务监听的端口号,在 Kubernetes 集群内部可以通过这个端口访问服务。
protocol: TCP # 指定端口使用的协议,这里是 TCP适用于大多数 web 服务和网络通信。
targetPort: 7001 # Pod 中容器监听的端口号。当请求到达 Service 时Service 会将流量转发到 Pod 的这个端口。
nodePort: 30701 # 当 Service 的类型是 NodePort 时nodePort 字段指定了在每个集群节点的 IP 上打开的端口,外部可以通过此端口访问服务。这个端口号应该是一个 1 到 65535 范围内的值,并且确保在节点上没有其他服务使用该端口。
# 在 Kubernetes 的 Service 配置中selector 是一个非常重要的字段。它定义了服务如何与 Pod 建立联系,即服务通过选择器来识别并转发流量到哪些 Pod 上。选择器是一个标签查询,用于匹配 Pod 的标签labels
1 year ago
selector:
app: gw-charge
tier: backend
sessionAffinity: None
type: NodePort