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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 表示使用的是 Kubernetes 的核心 API 版本 1这是最稳定和广泛使用的API版本之一通常用于Service、Pod、Namespace等核心资源。
apiVersion: v1
# Service 是一种核心资源,用于定义微服务架构中的服务访问策略。
kind: Service
# 资源的元数据信息
metadata:
# 组键值对用于标识和选择资源。标签可以用于组织资源、选择资源进行操作以及在Service中定义Pod的选择器。
labels:
# 用来选择和分组具有相同应用名称的资源。
app: gw-charge
name: gw-charge
namespace: yibin-charge
# 服务监听设置
spec:
ports:
- name: http
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
selector:
app: gw-charge
tier: backend
sessionAffinity: None
type: NodePort