1. Pod scale out
[문제]
* 작업 클러스터 : kubernetes-admin@kubernetes
- Expand the number of running Pods in "eshop-order" to 5.
. namespace : devops
. deployment : eshop-order
kubectl config use-context kubernetes-admin@kubernetes
kubectl get namspaces devops
kubectl get deployments.apps -n devops
kubectl scale deployment eshop-oerder --replicas=5 -n devops
kubectl get deploy -n devops
kubectl get pod -n devops
※ Scale 명령어는 아래 링크에서 참고
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#scale
2. deployment 생성하고 Scaling 하기
[문제]
* 작업 클러스터 : kubernetes-admin@kubernetes
- Create a deployment as follows:
- TASK :
. name : webserver
. 2 replicas
. label : app_env_stage=dev
. container name: webserver
. container images : nginx:1.14
- Scale Out Deployment.
. Scale the deployment webserver to 3 pods
kubectl config use-context kubernetes-admin@kubernetes
kubectl create deployment webserver --image=nginx:1.14 --replicas=2 --dry-run=client -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: webserver
name: webserver
spec:
replicas: 2
selector:
matchLabels:
app: webserver
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: webserver
spec:
containers:
- image: nginx:1.14
name: nginx
resources: {}
status: {}
kubectl create deployment webserver --image=nginx:1.14 --replicas=2 --dry-run=client -o yaml > webserver.yaml
# 아래와 같이 수정
cat webserver.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: webserver
spec:
replicas: 2
selector:
matchLabels:
app_env_stage: dev
template:
metadata:
labels:
app_env_stage: dev
spec:
containers:
- image: nginx:1.14
name: webserver
ports:
- containerPort: 80
kubectl apply -f webserver.yaml
deployment.apps/webserver created
kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
webserver 2/2 2 2 42s
kubectl get deployments.apps -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
webserver 2/2 2 2 51s webserver nginx:1.14 app_env_stage=dev
kubectl get pods
NAME READY STATUS RESTARTS AGE
webserver-c5b8f6c65-8ksqr 1/1 Running 0 68s
webserver-c5b8f6c65-p6mlb 1/1 Running 0 68s
kubectl scale deployment webserver --replicas=3
deployment.apps/webserver scaled
kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
webserver-c5b8f6c65-8ksqr 1/1 Running 0 118s app_env_stage=dev,pod-template-hash=c5b8f6c65
webserver-c5b8f6c65-9456q 1/1 Running 0 15s app_env_stage=dev,pod-template-hash=c5b8f6c65
webserver-c5b8f6c65-p6mlb 1/1 Running 0 118s app_env_stage=dev,pod-template-hash=c5b8f6c65
yaml 파일을 수정 후 apply 명령을 실행하다보면 아래와 같은 에러가 나타날때가 있다.
error: error parsing webserver.yaml: error converting YAML to JSON: yaml: line 18: found a tab character that violates indentation
:set list 를 통해 확인하면 tab으로 공백이 생겨서 그럴수 있다. 문제가 되는 공백을 제거한 다음 다시 apply 명령 실행시 정상적으로 된다.
[참고]
- 유투브 따배씨
'자격증 > CKA' 카테고리의 다른 글
[CKA] NodeSelector (0) | 2023.03.21 |
---|---|
[CKA] Rolling Update & Roll Back (0) | 2023.03.15 |
[CKA] Side-car Container Pod 실행 (0) | 2023.03.12 |
[CKA] multi-container Pod 생성 (0) | 2023.03.05 |
[CKA] Static Pod 생성 (0) | 2023.03.05 |