0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CKA試験、Deployment(命令語のみ)

Last updated at Posted at 2023-04-21

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?