k8s实践记录

项目部署到 k8s 中

通过deployment-go-hello2.yml创建副本为3的Deployment,更新策略默认使用滚动更新

apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-hello
spec:
  replicas: 3
  selector:
    matchLabels:
      app: go
  template:
    metadata:
      labels:
        app: go
    spec:
      containers:
      - name: hello
        image: go-helloworld:0.0.4
        ports:
        - containerPort: 8009   #让集群知道pod开放的端口
[root@k8s docker-go]# kubectl apply -f deployment-go-hello2.yml
deployment.apps/go-hello created
[root@k8s docker-go]# kubectl get deployment -o wide
NAME       READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES                SELECTOR
go-hello   3/3     3            3           6s    hello        go-helloworld:0.0.4   app=go

通过 service 把服务暴露出来,可以从外部直接访问

通过Service 中的LoadBalancer将pod端口映射到物理机

kind: Service
apiVersion: v1
metadata:
  name: service-hello
spec:
  type: LoadBalancer
  ports:
    - port: 8008  # 设置 Service 暴露的端口
      protocol: TCP
      targetPort: 8009  # 设置 Pod 的端口
      nodePort: 30081  # 设置 NodePort 的端口
  selector:
      app: go
[root@k8s docker-go]# kubectl create -f rc1server.yml
service/service-hello created

在这里插入图片描述

实践 k8s 的伸缩功能,实践 k8s 的滚动更新功能

滚动升级:kubectl set image deployment/go-hello hello=go-helloworld:0.0.7
在这里插入图片描述

扩充副本数:

[root@k8s docker-go]# kubectl edit deployment go-hello
deployment.extensions/go-hello edited
[root@k8s docker-go]# kubectl get deployment -o wide
NAME       READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES                SELECTOR
go-hello   5/5     5            5           4m49s   hello        go-helloworld:0.0.7   app=go
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值