Rancher CLI 사용

leesj·2021년 9월 29일
0

Rancher 의 기능을 GUI 와 더불어 CLI 로 사용학 위한 설정 및 사용법

  • 랜처 서버가 설치된 서버와 동일 서버에서 CLI 설정을 진행
  • 필요사항: 랜처 서버 URL, BearerToken

랜처 CLI download

$ wget https://github.com/rancher/cli/releases/download/v2.4.12/rancher-linux-amd64-v2.4.12.tar.gz

Rancher GUI 에서 API Key 생성

  • User Profile > Account & API Keys 메뉴로 진입

  • Scope 은 제한하지 않고 키를 생성
  • 생성 이후 생성된 각 키가 노출되는데 이것들은 별도의 공간에 복사해둠

CLI 인증

$ tar -xvf rancher-linux-amd64-v2.4.12.tar.gz
$ cd rancher-v2.4.12/
$ ./rancher login https://[URL] --token token-[BEARER_TOKEN]
  • 위 커맨드로 로그인 시도시 실패하는 경우가 있는데 2가지 정도로 원인을 분석 해 볼수 있다.
    1) cli 사용하려는 대상 서버(control role 을 가진) 의 443 포트로 접근이 가능한지 확인
    2) 쿠버네티스 cattle-system 네임스페이스를 확인하고 모든 pod 가 running 상태인지 확인

Project 선택

Do you want to continue connecting (yes/no)? yes
NUMBER    CLUSTER NAME       PROJECT ID        PROJECT NAME   PROJECT DESCRIPTION
1         cluster1   c-jd9j2:p-4zwbp   Default        Default project created for the cluster
2         cluster1   c-jd9j2:p-rj7lz   System         System project created for the cluster
3         local              local:p-8bdk6     System         System project created for the cluster
4         local              local:p-gp5c6     Default        Default project created for the cluste

kubectl install

rancher CLI 를 통해 kubectl 명령어 사용을 위해서는 kubectl 설치가 필요함

1) Download the latest release with the command

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   154  100   154    0     0    911      0 --:--:-- --:--:-- --:--:--   911
100 44.7M  100 44.7M    0     0  45.1M      0 --:--:-- --:--:-- --:--:-- 81.8M

2) Validate the binary (optional)

$ curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   154  100   154    0     0    900      0 --:--:-- --:--:-- --:--:--   900
100    64  100    64    0     0    156      0 --:--:-- --:--:-- --:--:--   156

$ echo "$(<kubectl.sha256) kubectl" | sha256sum --check
kubectl: OK

3) Install kubectl

$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

4) Test to ensure the version you installed is up-to-date

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

0개의 댓글