brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jan 04. 2020

28. CLI로 GKE 만들어 보기


<1>  CLI로 GKE 만들어 보기

<2> 생성 순서

<3> 생성법

<4>  서비스 확인

<5> 참고 



<1>  CLI로 GKE 만들어 보기

 

Nodes , Pod를 알아보자.

Pod는 1개의 서버 이다.  

마이크로 서비스를 쉽게 만들고 관리하기 위한 기술이다.




<2> 생성 순서


1. Cloud Console로 정보 확인

2. Zone 설정하기

3. 컨테이너 클러스터  만들기

4. 클러스터를 사용하기 위해  사용자 인증 정보를 얻기

5. 컨테이너에  애플리케이션 배포하기.

6. LoadBalncer로 외부 노출




<3> 생성법


1. Cloud Console로 정보 확인


반드시 내 계정과 프로젝트로 되어 있는지 확인하기 바란다.


gcloud auth list

gcloud config list project

// 소유자와 프로젝트가 지정되어 있는지 반드시 확인한다.


프로젝트 설정이 안되어 있다면 지정하자.

gcloud config set project just-lore-264018

 



2.   Zone 설정하기


gcloud config set compute/zone us-central1-a

// zone도 반드시 지정되어야 한다.


반드시 3가지 지정 필수.

내계정

프로젝트

zone지정


root@instance-1 terra]# gcloud config list






3. 컨테이너 클러스터  만들기


1)

gcloud container clusters create game-web01-ku01
gcloud container clusters create [CLUSTER-NAME]

gcloud container clusters list


gcloud auth login로  인증을 받아야 한다고 오류가 뜬다.
https 링크 클릭해 나온 값을 입력한다.


-----------------------------

ERROR: (gcloud.container.clusters.create) Your current active account [topasvga@kakao.com] does not have any valid credentials Please run: $ gcloud auth login to obtain new credentials. For service account, please activate it first: $ gcloud auth activate-service-account ACCOUNT

[root@instance-1 terra]# gcloud auth login You are running on a Google Compute Engine virtual machine. It is recommended that you use service accounts for authentication. You can run: $ gcloud config set account `ACCOUNT` to switch accounts if necessary. Your credentials may be visible to others with access to this virtual machine. Are you sure you want to authenticate with your personal account? Do you want to continue (Y/n)? Go to the following link in your browser: https:// xxxxxxxxxxxxxxxxxx


Enter verification code : yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy


`gcloud auth login` no longer writes application default credentials.

If you need to use ADC, see:

gcloud auth application-default --helpYou are now logged in as [topasvga@kakao.com].

Your current project is [just-lore-264018].


You can change this setting by running: 

$ gcloud config set project PROJECT_ID




2) 다시 컨터이너 클러스터 생성 시도

// 클러스터 이름은 문자로 시작  숫자로 끝나야 한다.


[root@instance-1 terra]# 

gcloud container clusters create game-web01-ku01

쿠버네티스 API를 사용할 수 있도록 Enable 하라고 에러가 뜬다.

URL을 클릭해서 쿠버네티스 API를 Enable 한다.


ERROR:

(gcloud.container.clusters.create) ResponseError: code=403, message=Kubernetes Engine API is not enabled for this project. Please ensure it is enabled in Google Cloud Console and try again: visit https://xxxxxxxxxxxxxxxxxxxxxxxxxxx


[root@instance-1 terra]# 

gcloud container clusters create game-web01-ku01


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:




생성 결과


game-web01-ku01 us-central1-a 1.13.11-gke.14 35.193.137.12 n1-standard-1 1.13.11-gke.14 3 RUNNING




4. 클러스터를 사용하기 위해  사용자 인증 정보를 얻기


gcloud container clusters get-credentials game-web01-ku01

gcloud container clusters get-credentials [CLUSTER-NAME]


Fetching cluster endpoint and auth data.

kubeconfig entry generated for game-web01-ku01.


// 앞으로 컨테이너에 배포하는것들은 위 인증정보를 얻은  ku01에  리소스가 생성된다.



5. 컨테이너에  애플리케이션 배포하기.

  

1) kubectl 설치하기

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl


chmod +x ./kubectl


sudo mv ./kubectl /usr/local/bin/kubectl


kubectl version


Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.11-gke.14", GitCommit:"56d89863d1033f9668ddd6e1c1aea81cd846ef88", GitTreeState:"clean", BuildDate:"2019-11-07T19:12:22Z", GoVersion:"go1.12.11b4", Compiler:"gc", Platform:"linux/amd64"}



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

deployment.apps/hello-server created


참고

https://kubernetes.io/docs/tasks/tools/install-kubectl/




6. LoadBalncer로 외부 노출


다음과 같은 kubectl expose 명령어를 실행하여 Kubernetes 서비스를 생성하자


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

service/hello-server exposed




<4>  서비스 확인


1. 확인

kubectl get service

NAME           TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGE
hello-server   LoadBalancer   10.35.249.140   35.222.18.54   8080:31569/TCP   94s
kubernetes     ClusterIP      10.35.240.1     <none>         443/TCP          12m


2

만들어진 서비스 웹브라우저로 확인

htto://35.222.18.54:8080

http://[EXTERNAL-IP]:8080


3

root@cloudshell:~ (just-lore-264018)$ kubectl get pods

NAME                                              READY   STATUS    RESTARTS   AGE

hello-server-64db4d4dc7-65gdn   1/1     Running   0          20h



4

# List all pods in ps output format with more information (such as node name).  

  kubectl get pods -o wide


  # List a single replication controller with specified NAME in ps output format.

  kubectl get replicationcontroller web


  # List deployments in JSON output format, in the "v1" version of the "apps" API group:

  kubectl get deployments.v1.apps -o json


  # List a single pod in JSON output format.

  kubectl get -o json pod web-pod-13je7


  # List a pod identified by type and name specified in "pod.yaml" in JSON output format.

  kubectl get -f pod.yaml -o json


  # Return only the phase value of the specified pod.

  kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}


  # List all replication controllers and services together in ps output format.

  kubectl get rc,services


  # List one or more resources by their type and names.

  kubectl get rc/web service/frontend pods/web-pod-13je7



5. 삭제


gcloud container clusters list


gcloud container clusters delete [CLUSTER-NAME]


gcloud container clusters delete  game-web01-ku01





<5> 참고 


gcloud container clusters create --machine-type=e2-medium --zone=xxxxxx    xxx-cluster 


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


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


gcloud container clusters delete xxx-cluster 




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


감사합니다.




매거진의 이전글 26. 가상서버 만드는법 2가지
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari