posts - 359,comments - 0,views - 19万

一、获取deployment 名称,一般pod 使用名称与之一致

1
kubectl get deploy -n test

 

 二、创建my-nginx所对应的svc,pod所对应的端口是8080,所以目标端口是8080

1
kubectl expose deployment my-nginx --port=30000 --target-port=8080 -n test

 

测试一下

 

 三、

如果需要外部能访问,需要修改svc的网络模式

编辑新创建的svc,type的类型由ClusterIP改成NodePort,保存退出即可

1
kubectl edit svc my-nginx -n test

 

 

 

 四、yaml文件创建

复制代码
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: test
  labels:
    name: web
spec:
  type: NodePort
  ports:
  - port: 8088 #集群内的pod互相通信用的端口类型
    targetPort: 80 #容器端口,访问容器内服务所用的端口
    nodePort: 30500 #对外暴露端口
  selector:
    app: web #选择器,选择标签


复制代码

 

posted on   属于我的梦,明明还在  阅读(2600)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示