K8s-yaml的使用及命令

Posted fuyuteng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K8s-yaml的使用及命令相关的知识,希望对你有一定的参考价值。

YAML配置文件管理对象
对象管理:
# 创建deployment资源
kubectl create -f nginx-deployment.yaml
# 查看deployment
kubectl get deploy
# 查看ReplicaSet
kubectl get rs
# 查看pods所有标签
kubectl get pods --show-labels
# 根据标签查看pods
kubectl get pods -l app=nginx
# 滚动更新镜像
kubectl set image deployment/nginx-deployment nginx=nginx:1.11
或者
kubectl edit deployment/nginx-deployment
或者
kubectl apply -f nginx-deployment.yaml
# 实时观察发布状态:
kubectl rollout status deployment/nginx-deployment
# 查看deployment历史修订版本
kubectl rollout history deployment/nginx-deployment
kubectl rollout history deployment/nginx-deployment --revision=3
# 回滚到以前版本
kubectl rollout undo deployment/nginx-deployment
kubectl rollout undo deployment/nginx-deployment --to-revision=3
# 扩容deployment的Pod副本数量
kubectl scale deployment nginx-deployment --replicas=10
# 设置启动扩容/缩容
kubectl autoscale deployment nginx-deployment --min=10 --max=15 --cpu-percent=80

 

发布服务:
# cat nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
ports:
- port: 88
targetPort: 80
selector:
app: nginx
清理:
# kubectl delete -f nginx-deployment.yaml
# kubectl delete -f nginx-service.yaml

 

以上是关于K8s-yaml的使用及命令的主要内容,如果未能解决你的问题,请参考以下文章

k8s-YAML配置文件(转)

K8S-yaml配置文件详解

k8s-yaml文件

K8S 之 Dashboard安装

VSCode自定义代码片段——cli的终端命令大全

VSCode自定义代码片段4——cli的终端命令大全