kubectl deployment
チートシート
deployment 作成
kubectl create deployment (deployment name) --image=(image name):(version)
deployment scale調整
kubectl scale deployment (deployment name) --replicas=5 --record
deployemnt のバージョン更新
kubectl set image deployment (deployment name) (container_name)=(image):(image version) --recrod
例)
kubectl create deployment webserver --image=nginx:1.14 --dry-run=client -o yaml > 7.yaml
vi 7.yaml
編集前 7.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: webserver
name: webserver
spec:
replicas: 1
selector:
matchLabels:
app: webserver
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: webserver
spec:
containers:
- image: nginx:1.14
name: nginx
resources: {}
status: {}
編集後 7.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: webserver
name: webserver
spec:
replicas: 5
selector:
matchLabels:
app: webserver
template:
metadata:
labels:
app: webserver
spec:
containers:
- image: nginx:1.14
name: container-nginx
# ファイルを適応
kubectl apply -f ./7.yaml
# deployment.apps/webserver created
# scale 調整
kubectl scale deployment --replicas=2 --record
# deployment.apps/webserver scaled
# imageのバージョン変更
kubectl set image deployment webserver container-nginx=nginx:1.15 --record
# deployment.apps/webserver image updated
kubectl set image deployment
kubectl scale deployment
deploymentを前のバージョンに戻す
kubectl rollout history deployment (deployment name)
kubectl rollout undo deployment (deployment name)
kubectl rollout undo deployment (deployment name) --to-revision=(number)
例)
# 履歴の確認
kubectl rollout history deployment webserver
# deployment.apps/webserver
# REVISION CHANGE-CAUSE
# 1 <none>
# 2 kubectl set image deployment webserver container-nginx=nginx:1.15 --record=true
# Deploymentの戻し
kubectl rollout undo deployment webserver --to-revision=1
# deployment.apps/webserver rolled back