Kubernetesの基本的なメモ
目次
Nodeの確認
協調してPodを動かしているサーバを確認
kubectl get nodes
Podの確認
# PODを確認
kubectl get pod
# すべてのPODを確認
kubectl get pod --all-namespaces
# deploy先を確認
kubectl get pod --output=wide
Podの中身を確認
kubectl describe pod {pod_name}
サービスの確認
kubectl get {service_name}
ロールバック手順
manifest.ymlファイルの作成
apiVersion: apps/v1
kind: Deployment
metadata:
name: testpj-deployment
labels:
app: testpj-deployment
spec:
replicas: 2
selector:
matchLabels:
app: testpj-app
template:
metadata:
labels:
app: testpj-app
spec:
containers:
- name: testpj-app
image: u01:5000/testpj:0.2
imagePullPolicy: Always
ports:
- name: testpj-app
containerPort: 4000
protocol: TCP
manifestを使ってデプロイ
kubectl apply -f manifest.yml
kubectl get pods
kubectl describe pods
kubectl describe podsの結果
Containers:
testpj-app:
Container ID: docker://895d87ba55af981ffcc32ff0dbbb313368308550488a30d90ec554e04a8ca1c4
Image: u01:5000/testpj:0.2
Image ID: docker-pullable://u01:5000/testpj@sha256:a5b921e2100961431090e67efd2492a071ad49ccf97a0ed82a35f52748eee58e
Port: 4000/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 11 Feb 2022 04:39:31 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c446w (ro)
イメージの更新
kubectl set image deployments/testpj-deployment testpj-app=u01:5000/testpj:0.3 --record=true
更新結果の確認
Containers:
testpj-app:
Container ID: docker://765403def9740b8ec88d4c1f0a1e5c8648751c53aa4850ea8cc925ec133d752b
Image: u01:5000/testpj:0.3
Image ID: docker-pullable://u01:5000/testpj@sha256:52c00bbd3fa700ef8d63232b8687f923e90e7d10080cc00bc2eb63e5fdc0e8bf
Port: 4000/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 11 Feb 2022 04:41:29 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-fnbxt (ro)
更新履歴の確認
kubectl rollout history deployment.apps/testpj-deployment
deployment.apps/testpj-deployment
REVISION CHANGE-CAUSE
4 <none>
9 <none>
11 kubectl set image deployments/testpj-deployment testpj-app=u01:5000/testpj:0.3 --record=true
12 kubectl set image deployments/testpj-deployment testpj-app=u01:5000/testpj:0.3 --record=true
ロールバック
kubectl rollout undo deployment.app/testpj-deployment