k8s基础命令

该文详细介绍了如何使用kubectl命令管理Kubernetes集群中的应用,包括列出部署和Pods、查看应用版本、更新应用、检查服务状态、回滚版本、扩展部署、负载均衡以及暴露应用到NodePort。
摘要由CSDN通过智能技术生成

0. list all deployments & pods:

kubectl get deployments
kubectl get pods

1. view current app version:

kubectl describe pods

2. update your app

kubectl set image deployments/deploymentName deploymentName=jocatalin/deploymentName:newVersion

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

check that app is running, view the exposed ip & port

kubectl describe services/deploymentName

kubectl describe services/kubernetes-bootcamp

confirm update status:

kubectl rollout status deployments/kubernetes-bootcamp

roll back to previous version:

kubectl rollout undo deployments/kubernetes-bootcamp

3. expand the deployments

view the replicates that deployment created.

kubectl get rs

scale the deployment:

kubectl scale deployments/kubernetes-bootcamp --replicas=4

view the number of pods

kubectl get pods -o wide

Create an environment variable called NODE_PORT that has a value as the Node port:

export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT

Next, we’ll do a curl to the exposed IP and port. Execute the command multiple times:

curl $(minikube ip):$NODE_PORT

We hit a different Pod with every request. This demonstrates that the load-balancing is working.

4. exposed your app

list the services of our cluster:

kubectl get services
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值