코알못

[Kubernetes & Docker] Kuberneties 구성 본문

BIG DATA

[Kubernetes & Docker] Kuberneties 구성

코린이s 2023. 2. 9. 22:33
728x90

이번 시간에는 구글 쿠버네티스 클러스터 구성하도록 한다!

아래와 같이 google cloud 에 접속한뒤 콘솔에서 클러스터 만들기를 선택한다.

자동 관리가 아닌 사용자가 직접 관리 하도록 할 예정이며 아래 화면과 같이 클릭한다.

원하는 클러스터명을 기재한다.

ㅡㄹ

노드의 경우 3개로 구성 하도록 한다.

10분 정도 기다리면 클러스터가 생성 되며 초기 셋팅을 위해 연결을 클릭한다.

gcloud 라는 google CLI 를 이용하여 클라우드 구성 가능하며 화면에 나오는 명령어를 복사한다.

만약 shell이 로컬에 설치되어 있지 않다면 구글에서 브라우저 shell 인 cloud shell 제공 하고 있어 제공하는 쉘을 이용해도 된다.

cloud shell 을 이용하면 해당 쉘에 gcloud, kubectl 이 설치 되어 있어 설치 할 필요 없으며

로컬의 쉘을 이용한다면 gcloud, kubectl을 설치 해야 하므로 아래 사이트 참고하여 먼저 설치 한다.

- gcloud 설치 관련 사이트 : https://cloud.google.com/sdk/docs/install?hl=ko 

 

gcloud CLI 설치  |  Google Cloud

gcloud CLI 설치 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 페이지에는 Google Cloud CLI 설치를 선택하고 유지하기 위한 안내가 포함되어 있습니다. Google Cl

cloud.google.com

로컬에 압축 파일 다운로드후 아래 쉘 파일을 실행한다.

// 설치
$ ./google-cloud-sdk/install.sh
// 초기화 (사용하고 있는 프로젝트, 계정을 선택한다.)
$ ./google-cloud-sdk/bin/gcloud init

- kubectl 설치 관련 사이트 : https://kubernetes.io/ko/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos

 

macOS에 kubectl 설치 및 설정

시작하기 전에 클러스터의 마이너(minor) 버전 차이 내에 있는 kubectl 버전을 사용해야 한다. 예를 들어, v1.26 클라이언트는 v1.25, v1.26, v1.27의 컨트롤 플레인과 연동될 수 있다. 호환되는 최신 버전

kubernetes.io

 

// 설치
$ brew install kubectl
// 확인
$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"darwin/amd64"}

 kuberneties 클러스터 설정을 진행해야 하며, 아래 설정 관련 파일 확인시 아무 설정이 되어 있지 않다.

$ cat ~/.kube/config

처음 UI 에서 제공한 gcloud 명령어를 호출하여 클러스터 설정 진행한다.

만약 정상적으로 설정 됐다면 아래와 같이 클러스터 정보 확인 가능하다.

$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: abcd <인증서 base64로 인코딩한 데이터>
    server: https://35.1.1.2 <마스터 노드의 API Server 주소>
  name: gke_reference-lens-1234_asia-east1-a_corin-cluster
contexts:
- context:
    cluster: gke_reference-lens-1234_asia-east1-a_corin-cluster
    user: gke_reference-lens-1234_asia-east1-a_corin-cluster
  name: gke_reference-lens-1234_asia-east1-a_corin-cluster
current-context: gke_reference-lens-1234_asia-east1-a_corin-cluster
kind: Config
preferences: {}
users:
- name: gke_reference-lens-1234_asia-east1-a_corin-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      command: gke-gcloud-auth-plugin
      installHint: Install gke-gcloud-auth-plugin for use with kubectl by following
        https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
      provideClusterInfo: true

 

kubectl 명령어를 호출해보면 접속 까지는 잘 되는것을 볼 수 있다.

$ kubectl get pod
No resources found in default namespace.

끝!

 

# 오류

1) permission 오류

- 원인 : 클러스터에 권한이 없음

ResponseError: code=403, message=Required "container.clusters.get" permission(s)

- 해결 : gcloud init 명령어로 해당 클러스터, 유저로 정상 셋팅 했는지 재 확인한다. 저자의 경우 로그인을 잘못했다.

2) 플러그인 미 설치 이슈

- 원인 : 플러그인 gke-gcloud-auth-plugin 미 설치

Unable to connect to the server: getting credentials: exec: executable gke-gcloud-auth-plugin not found

It looks like you are trying to use a client-go credential plugin that is not installed.

To learn more about this feature, consult the documentation available at:
      https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins

Install gke-gcloud-auth-plugin for use with kubectl by following https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke

- 해결 : 플러그인 설치

$ gcloud components install gke-gcloud-auth-plugin
728x90
Comments