brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 26. 2022

179. 클라우드 쉘로 GKE생성(4/6)


<1> 기본 환경 설정

<2> GKE 클러스터 생성

<3> 배포

<4> 테스트 완료후 클러스터 삭제




<1> 기본 환경 설정


1

cloud shell 실행


2

gcloud auth list

승인


gcloud config list project


gcloud config set compute/zone us-central1-a



3

설정 확인

gcloud config list




<2> GKE 클러스터 생성


1

gcloud container clusters create [CLUSTER-NAME]


gcloud container clusters create blockgame-gcp-k8s

(3분 걸림)



2

kubectl get nodes

NAME                                               STATUS   ROLES    AGE   VERSION

gke-blockgame-gcp-k8s-default-pool-dae32566-frjs   Ready    <none>   65s   v1.21.6-gke.1503

gke-blockgame-gcp-k8s-default-pool-dae32566-htvv   Ready    <none>   71s   v1.21.6-gke.1503

gke-blockgame-gcp-k8s-default-pool-dae32566-vjkj   Ready    <none>   66s   v1.21.6-gke.1503



3

참고 사항

콘솔을 통해 클러스터를 만든경우

Kubectl api 사용 설정을 수동으로 해야만 kubectl 명령을 사용할 수 있습니다.

gcloud 명령어가 kubeconfig파일을 자동으로 업데이트 합니다.


gcloud container clusters get-credentials [CLUSTER-NAME]


gcloud container clusters get-credentials blockgame-gcp-k8s

Fetching cluster endpoint and auth data.

kubeconfig entry generated for blockgame-gcp-k8s.




<3> 모니터링과 배포


1

모니터링?

Cloud shell 하다더 띠우고  모니터링


watch -d kubectl get deploy,svc,pods



2

배포

kubectl create deployment block-server --image=gcr.io/google-samples/hello-app:1.0


3

로드밸런서 연결

kubectl expose deployment block-server --type=LoadBalancer --port 80


4

모니터링 확인

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/block-server   1/1     1            1           2m12s

NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)        AGE

service/block-server   LoadBalancer   10.112.15.137   35.225.116.193   80:30248/TCP   2m4s

service/kubernetes     ClusterIP      10.112.0.1      <none>           443/TCP        8m18s

NAME                                READY   STATUS    RESTARTS   AGE

pod/block-server-7cf8fd798f-jxmcs   1/1     Running   0          2m13s



서비스 확인

kubectl get service



5

웹프라우저로 접속해 보기

안된다 - -

80은 안되네요..


6

다시 생성


 kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0


kubectl expose deployment hello-server --type=LoadBalancer --port 8080


NAME                           READY   UP-TO-DATE   AVAILABLE   AGE

Every 2.0s: kubectl get deploy,svc,pods                                                                                                                                                         cs-797573607414-default: Tue Apr 26 07:53:57 2022

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/block-server   1/1     1            1           56m

deployment.apps/hello-server   1/1     1            1           4m16s

NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE

service/block-server   LoadBalancer   10.112.10.249   35.223.81.55     8080:31842/TCP   6m17s

service/hello-server   LoadBalancer   10.112.2.140    35.225.116.193   8080:31808/TCP   2m27s

service/kubernetes     ClusterIP      10.112.0.1      <none>           443/TCP          63m

NAME                                READY   STATUS    RESTARTS   AGE

pod/block-server-7cf8fd798f-jxmcs   1/1     Running   0          56m

pod/hello-server-76d47868b4-qrfvg   1/1     Running   0          4m15s



웹프라우저로 접속해 보기

잘 된다!!

8080은 잘 된다.


<4> 테스트 완료후 클러스터 삭제


gcloud container clusters delete [CLUSTER-NAME]


gcloud container clusters delete blockgame-gcp-k8s

<엔터>

The following clusters will be deleted.

 - [blockgame-gcp-k8s] in [us-central1-a]

Do you want to continue (Y/n)?

Deleting cluster blockgame-gcp-k8s...working...





다음 공부

https://brunch.co.kr/@topasvga/2393





https://brunch.co.kr/@topasvga/1833



https://brunch.co.kr/@topasvga/2395



감사합니다.



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