GKE 에 SSH 접속하기

알파로그·2023년 12월 27일
0

Cloud Computing Service

목록 보기
15/15

✏️ 연결이 안되는 경우

  • GKE 를 좀 더 디테일하게 사용하기 위해서 VM 인스턴스를 사용해 연결하려고 했지만 아래와 같은 오류가 발생했다.
WARNING: Accessing a Kubernetes Engine cluster requires the kubernetes commandline
client [kubectl]. To install, run
$ gcloud components install kubectl

Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials) ResponseError: code=403, message=Request had insufficient authentication scopes.

If you are in a compute engine VM, it is likely that the specified scopes during VM creation are not enough to run this command.
See https://cloud.google.com/compute/docs/access/service-accounts#accesscopesiam for more information about access scopes.
See https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes for how to update access scopes of the VM.
  • 원인을 찾아보니 VM 인스턴스가 접근할 수 있는 GCP 의 다양한 API 가 있는데,
    GKE 에 접근하기 위한 API 호출 권한이 없기 때문이라고 한다.

✏️ VM 인스턴스 생성

📍 API 권한 추가

  • 이미 생성된 VM 인스턴스를 수정하는 것은 복잡하다고 해서 인스턴스를 새롭게 생성했다.
    • ID 및 API 액세스 → 액세스 범위 → 각 API 에 액세스 설정 선택

  • Cloud Platform → 사용 설정됨 선택

✏️ GKE 연결

📍 gke-gcloud-auth-plugin 설치

🔗 gke-gcloud-auth-plugin 공식 문서

  • GKE v1.26 부터는 새롭게 변경된 별도의 인증 플러그인을 설치하고 사용해야 한다.
    • 아래의 명령어로 플러그인을 설치할 수 있다.
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin

📍 gcloud CLI 설치

🔗 공식 문서

  • 자신의 환경에 맞는 CLI 버전을 설치해야 한다.
# 버전 확인
getconf LONG_BIT
# 파일 다운로드
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-444.0.0-linux-arm.tar.gz

# 압축 풀기
tar -xf google-cloud-cli-444.0.0-linux-arm.tar.gz

# 설치
./google-cloud-sdk/install.sh

📍 kubectl 설치

  • kubectl 을 설치해야 GKE 와 연결될 수 있다.
    • centos 7 을 선택했기 때문에 당연히 yum 으로 설치를 해야될텐데 이번엔 이상하게 yum, dnf 으로 명령 해봐도 아래의 오류가 발생했다.
sudo: yum: command not found
  • ubuntu 의 명령어인 apt 를 업데이트 해봤더니 정상적으로 실행되어서 apt 를 사용해 Kubectl 을 설치했다.
sudo apt-get install kubectl

✏️ 기본 세팅

📍 Debian 에서 Docker 설치

  • software-properties-common 패키지 설치
apt-get update
apt-get install software-properties-common
  • docker 공식 GPR 키 추가
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
  • docker APT 저장소 추가
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  • 패키지 목록 업데이트
apt-get update
  • Docker CE 설치
apt-get install docker-ce
  • 설치 확인
docker --version

📍 Git 설치

sudo apt-get install git
sudo apt install git
git --version
profile
잘못된 내용 PR 환영

0개의 댓글