1. 程式人生 > >K8s-yaml的使用及命令

K8s-yaml的使用及命令

-m 實時 label span col app 啟動 metadata cto

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的使用及命令