> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siflow.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建和管理 Service

> 为一组 Pod 创建稳定的访问入口，并查看或删除不再使用的 Service。

Service 通过标签选择一组 Pod，并为这些 Pod 提供稳定的访问地址。工作负载扩缩容或 Pod 发生变化时，访问方仍可通过 Service 访问符合选择条件的 Pod。需要使用 Ingress 配置 HTTP 或 HTTPS 路由时，也应先创建作为后端的 Service。

## 创建 Service

1. 登录 [GPU 云服务控制台](https://console.siflow.cn/gpu-cloud/home)，进入 **集群** 页面。

2. 单击目标集群名称，进入集群工作台。

3. 在左侧导航中进入 **网络** 页面，并切换到 **服务** 页签。

4. 单击 **创建**。

<img src="https://mintcdn.com/siflow/Z3oydoQ8jnJ7q_Ig/gpu-cloud/media/cluster-network-service.png?fit=max&auto=format&n=Z3oydoQ8jnJ7q_Ig&q=85&s=ea2d9966808e95bda2df0ff59f9d0953" alt="创建 Service" width="3840" height="1858" data-path="gpu-cloud/media/cluster-network-service.png" />

5. 配置 Service。

   | 参数 | 说明 |
   | - | - |
   | **Name** | 设置 Service 名称。名称应能体现所访问的应用或工作负载。 |
   | **Namespace** | 选择 Service 所属命名空间。通过标签选择 Pod 时，Service 与 Pod 应位于同一命名空间。 |
   | **Labels** | 可选。为 Service 资源添加标签，用于标识或筛选 Service。这里的标签不会决定流量转发到哪些 Pod。 |
   | **Spec (YAML)** | 填写 Service 的 Kubernetes spec，只填写 `spec` 下的内容，不需要填写 `apiVersion`、`kind` 或 `metadata`。其中，`selector` 用于选择后端 Pod，`ports` 用于配置 Service 端口与 Pod 端口的映射关系。 |

   以下示例创建一个 `ClusterIP` 类型的 Service，将 Service 的 80 端口转发到带有 `app: example-app` 标签的 Pod 的 8080 端口。`ClusterIP` 适合在集群内部访问工作负载，也可以作为 Ingress 的后端 Service。

   ```yaml theme={null}
   type: ClusterIP
   selector:
     app: example-app
   ports:
     - name: http
       protocol: TCP
       port: 80
       targetPort: 8080
   ```

   请根据工作负载的实际标签和监听端口修改示例：

   | 字段 | 说明 |
   | - | - |
   | `type` | Service 类型。示例使用 `ClusterIP`，仅提供集群内部访问入口。 |
   | `selector` | 选择作为后端的 Pod。键值必须与目标 Pod 的标签一致，否则 Service 无法将请求转发到目标 Pod。 |
   | `port` | Service 对访问方提供的端口。 |
   | `targetPort` | 后端 Pod 中应用实际监听的端口。 |

6. 单击 **Create**，然后确认 Service 已创建。

## 查看 Service

1. 在 **服务** 页签中，按命名空间筛选或使用搜索框定位目标 Service。

2. 在目标 Service 的 **操作** 列中单击 **查看**。

3. 检查 Service 类型、标签选择器和端口映射，确认其指向预期的 Pod 和应用端口。

如果 Service 已创建但无法访问工作负载，请优先检查 `selector` 是否与 Pod 标签一致，以及 `targetPort` 是否为应用实际监听的端口。

## 删除 Service

<Warning>
  删除 Service 会移除该 Service 提供的访问入口，并中断依赖它的集群内访问或 Ingress 路由。删除 Service 不会删除其后端 Pod。
</Warning>

1. 在 **服务** 页签中找到目标 Service。

2. 在目标 Service 的 **操作** 列中单击 **删除**。

3. 确认删除。

需要通过域名或路径提供 HTTP 或 HTTPS 访问时，请参见 [使用 Ingress 暴露集群服务](/gpu-cloud/cluster/expose-services-with-ingress)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.