brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Aug 15. 2021

159. GCP 쿠버네티스 CLI로 만들기-2021


Google Cloud  쿠버네티스 클러스터 만들고 사용해보자~

CLI로 만들어 보자


<1> 계정 확인

<2> 프로젝트 확인

<3> 배포

<4> 배포 확인

<5> 클러스터 삭제하기

<10> 깉이 보면 좋을 사이트





<1> 계정 확인


1

cloud shell 사용


2

gcloud auth list


$ gcloud auth list

           Credentialed Accounts

ACTIVE  ACCOUNT


To set the active account, run:

    $ gcloud config set account `ACCOUNT`



3

실습 참고 사이트

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




<2> 프로젝트 확인


1

GCP는 프로젝트 단위로 실행된다.

gcloud config list project


$ gcloud config list project

[core]

project = xxxxxx-gcp-01-xxxxxxxxxx


Your active configuration is: [cloudshell-xxxx]


2

생성 지역 선택

gcloud config set compute/zone us-central1-a


$ gcloud config set compute/zone us-central1-a

Updated property [compute/zone].


3

클러스터 생성

gcloud container clusters create seo-k8s-1


$ gcloud container clusters create seo-k8s-1

WARNING: Starting in January 2021, clusters will use the Regular release channel by default when `--cluster-version`, `--release-channel`, `--no-enable-autoupgrade`, and `--no-enable-autorepair` flags are not specified.

WARNING: Currently VPC-native is not the default mode during cluster creation. In the future, this will become the default mode and can be disabled using `--no-enable-ip-alias` flag. Use `--[no-]enable-ip-alias` flag to suppress this warning.

WARNING: Starting with version 1.18, clusters will have shielded GKE nodes by default.

WARNING: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).

WARNING: Starting with version 1.19, newly created clusters and node-pools will have COS_CONTAINERD as the default node image when no image type is specified.

Creating cluster seo-k8s-1 in us-central1-a...done.

Created [https://container.googleapis.com/v1/projects/xxxxxxxx-gcp-01-xxxxxxx/zones/us-central1-a/clusters/seo-k8s-1].

To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/seo-k8s-1?project=xxxxxxxx-gcp-01-xxxxxxxxxx

kubeconfig entry generated for seo-k8s-1.


NAME LOCATIONMASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VER NUM_NODES STATUS

seo-k8s-1 us-central1-a 1.20.8-gke.900 34.123.55.192 e2-medium  1.20.8-gke.900  3    RUNNING


(5분 소요)


4

클러스터 사용자 인증하기

gcloud container clusters get-credentials [CLUSTER-NAME]

gcloud container clusters get-credentials seo-k8s-1


 $ gcloud container clusters get-credentials seo-k8s-1

Fetching cluster endpoint and auth data.

kubeconfig entry generated for seo-k8s-1.



<3> 배포


1

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


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

deployment.apps/hello-server created


2

서비스 만들기

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


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

service/hello-server exposed


3

서비스 생성 확인

kubectl get service


$ kubectl get service

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

hello-server   LoadBalancer   10.3.253.24   <pending>     8080:32612/TCP   14s

kubernetes     ClusterIP      10.3.240.1    <none>        443/TCP          8m9s


2분후 다시

kubectl get service

공인 ip 나옴


$ kubectl get service

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

hello-server   LoadBalancer   10.3.253.24   35.238.154.13   8080:32612/TCP   97s

kubernetes     ClusterIP      10.3.240.1    <none>          443/TCP          9m32s




<4> 배포 확인


1

웹브라우저로 접속 해보기

http://[EXTERNAL-IP]:8080

35.238.154.13:8080


Hello, world!

Version: 1.0.0




<5> 클러스터 삭제하기


1

gcloud container clusters delete [CLUSTER-NAME]

gcloud container clusters delete  seo-k8s-1


$ gcloud container clusters delete  seo-k8s-1

The following clusters will be deleted.

 - [seo-k8s-1] in [us-central1-a]


Do you want to continue (Y/n)?  y

Deleting cluster seo-k8s-1...⠛


(5분 소요)

Deleting cluster seo-k8s-1...done.

Deleted [https://container.googleapis.com/v1/projects/xxx-gcp-01-xxxxxb/zones/us-central1-a/clusters/seo-k8s-1].





<10> 깉이 보면 좋을 사이트

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



감사합니다.









매거진의 이전글 158. Google Cloud GCP 도커 (이론)
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari