深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 162|回复: 0
打印 上一主题 下一主题

Kubernetes service操作命令

[复制链接]

228

主题

466

帖子

2184

积分

版主

Rank: 7Rank: 7Rank: 7

积分
2184
跳转到指定楼层
楼主
发表于 2024-8-4 15:16:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1. 创建 Service:
使用 kubectl apply 命令通过 YAML 文件创建一个 Service。
  1. kubectl apply -f my-service.yaml
复制代码

2. 查看所有 Services:
使用 kubectl get services 命令查看集群中的所有 Services。
  1. kubectl get services
复制代码

3. 查看 Service 的详细信息:
使用 kubectl describe service 命令查看特定 Service 的详细信息。
  1. kubectl describe service my-service
复制代码

4. 查看 Service 的 Endpoints:
使用 kubectl get endpoints 命令查看特定 Service 的 Endpoints。
  1. kubectl get endpoints my-service
复制代码

5. 暴露 Deployment 为 Service:
使用 kubectl expose 命令将一个 Deployment 暴露为 Service。
  1. kubectl expose deployment my-deployment --port=80 --target-port=8080 --type=LoadBalancer
复制代码

6. 删除 Service:
使用 kubectl delete service 命令删除一个 Service。
  1. kubectl delete service my-service
复制代码

7. 更新 Service:
可以通过修改 Service 的 YAML 文件来更新其配置,然后使用 kubectl apply 命令应用更新。
  1. kubectl apply -f my-updated-service.yaml
复制代码

8.端口转发到 Service:
使用 kubectl port-forward 命令将本地端口和 Service 之间建立一个临时的端口转发。
  1. kubectl port-forward service/my-service 8080:80
复制代码

9. 为 Service 添加标签:
使用 kubectl label service 命令为 Service 添加标签,以便进行选择器匹配。
  1. kubectl label service my-service app=my-app
复制代码

10. 删除 Service 的 Endpoints:
使用 kubectl delete endpoints 命令删除特定 Service 的 Endpoints。
  1. kubectl delete endpoints my-service
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 02:26 , Processed in 0.023826 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表