brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jan 10. 2022

75.  Pod Autoscaler 사용하기-4/5

(작성중)


운영중인 Pod에 대해 자동으로 증가 되도록 해보자~

어플리케이션 서버를 자동 증가 시키는 것이다.


<1> 부하룰 주는 컨테이너 이미지 생성

<2> pod 생성

<3> cpu 사용룰 증가하면 pod 증가 시키기

<4> 부하 증가해서 확인하기



<1> 부하룰 주는 컨테이너 이미지 생성


mkdir 7

cd 7


1

vi index.php

<?php

 $x = 0.0001;

 for ($i = 0; $i <= 1000000; $i++) {

 $x += sqrt($x);

 }

 echo "OK!";

?>



2

빌드

docker build -t hpa_example .



docker images

[root@s17e3bbc1fd7 ~]# docker images

REPOSITORY                                        TAG       IMAGE ID       CREATED        SIZE

image_apache_2                                    latest    f849bab1a9f6   4 hours ago    521MB

m6n7b87w.kr.ncr.ntruss.com/image_apache_2         1.0       f849bab1a9f6   4 hours ago    521MB

hpa_example                                       latest    f9b6f1e04c74   17 hours ago   141MB



3

레지스트리 로그온하기

docker login -u <access-key-id> <private-endpoint>.kr.ncr.ntruss.com

Password : <secret-key>

Login Succeeded


docker login -u tUe  m6n7b87w.kr.private-ncr.ntruss.com

Password:

Login Succeeded


4

태그

docker image tag hpa_example <private-endpoint>/hpa_example:1.0

docker image tag hpa_example m6n7b87w.kr.private-ncr.ntruss.com/hpa_example:1.0


5

도커 이미지 올리기~

docker push <private-endpoint>/hpa_example:1.0


docker push m6n7b87w.kr.private-ncr.ntruss.com/hpa_example:1.0




6

콘솔에서 확인하기

VPC > Container Registry

hpa_example


hpa_examhpa_exampleple


<2> pod 생성


사용할 Pod 


1

vi hpa-php.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

 name: php-apache

spec:

 selector:

 matchLabels:

 run: php-apache

 replicas: 1

 template:

 metadata:

 labels:

 run: php-apache

 spec:

 containers:

 - name: php-apache

 image: <private-endpoint>/hpa_example:1.0

 imagePullPolicy: Always

 ports:

 - containerPort: 80

 resources:

 limits:

 cpu: 500m

 requests:

 cpu: 200m

 imagePullSecrets:

 - name: regcred

---

apiVersion: v1

kind: Service

metadata:

 name: php-apache

 labels:

 run: php-apache

spec:

 ports:

 - port: 80

 selector:

 run: php-apache  



2

kubectl create -f hpa-php.yaml


[root@s17e3bbc1fd7 7]# kubectl create -f hpa-php.yaml

error: error validating "hpa-php.yaml": error validating data: apiVersion not set; if you choose to ignore these errors, turn validation off with --validate=false


[root@s17e3bbc1fd7 7]# kubectl create -f hpa-php.yaml --validate=false

service/php-apache created

error: unable to recognize "hpa-php.yaml": no matches for kind "Deployment" in version ""



kubectl get deployments

kubectl get pods

kubectl get service





<3> cpu 사용룰 증가하면 pod 증가 시키기


kubectl autoscale deployment php-apache --cpu-percent=30 --min=1 --max=10


kubectl get hpa




<4> 부하 증가해서 확인하기


kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep

0.01; do wget -q -O- http://php-apache; done"



감사합니다.



브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari