brunch

You can make anything
by writing

- C.S.Lewis -

by 클라우드 엔지니어 Jan 04. 2020

28. 쿠버네티스 한번 만들어보기

<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[root@instance-1 terra]#



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:

Newly created clusters and node-pools will have node auto-upgrade enabled by default.

This can be disabled using the `--no-enable-autoupgrade` flag.

WARNING:

Starting in 1.12, default node pools in new clusters will have their legacy Compute Engine instance metadata endpoints disabled by default.

To create a cluster with legacy instance metadata endpoints disabled in the default node pool, run `clusters create` with the flag `--metadata disable-legacy-endpoints=true`.

WARNING:

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

This will enable the autorepair feature for nodes.

Please see https://cloud.google.com/kubernetes-engine/docs/node-auto-repair for more information on node autorepairs.



생성 결과


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


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

htto://35.222.18.54:8080

http://[EXTERNAL-IP]:8080



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

NAME                                              READY   STATUS    RESTARTS   AGE

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



# 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



2. 삭제


gcloud container clusters list


gcloud container clusters delete  game-web01-ku01

gcloud container clusters delete [CLUSTER-NAME]



감사합니다.




매거진의 이전글 27. 테라폼으로 VPC 만들기

매거진 선택

키워드 선택 0 / 3 0
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari
;