본문 바로가기

Infra/Kubernetes

1. 쿠버네티스 관련 설정 및 설치

1. GCP 설정

  • Compute Engine 활성화
    • https://console.cloud.google.com/compute
    • https:// cloud.google.com/compute/docs/?hl=ko (공식문서)
  • Instance 5개 살리기
    • OS : Ubuntu 16.04 LTS

유저는 SSH를 통해 Instance1에 접속하게 할것이며 
나머지 Instance는 Instance1을 통해 접속하게 할것이다

 

 

  • Instance에 Key 생성 및 Public Key 등록
    • ssh-keygen -t rsa
    • cat .ssh/id_rsa.pub을 통해 공개키 복사
    • Instance 2~5에 public key만들기
  • 설정을 모두 정상적으로 맞춰놨다면 Instance1을 통해 Instance2~5에 접속이 가능할것이다.

 

2. Kubespray 설치

Instance1 서버에서 

3. Kubespray 설정

  • 샘플 템플릿 복사해서 mycluster 만들기
    • cp -rfp inventory/sample inventory/mycluster
      • group_vars 는 클러스터 설치에 필요한 설정 내용이 있다
        • all: 어느 환경에 어느 설정을 적용할지 설정
        • etcd.yml: etcd설치에 필요한 상세 설정 내용
        • k8s-cluster: 쿠버네티스 관련 설정
      • inventory.ini 설치 대상 서버들의 정보를 설정한다 (아래 Code Block 참고)
      • 쿠버네티스 클러스터 구성 명령어
        • ansible-palybook -i inventory/mycluster/inventory.ini -v --become --become-user=root cluster.yml
# Nodes to be 
[all]
instance-1 ansible_ssh_host=10.128.0.2 ip=10.128.0.2 etcd_member_name=etcd1
instance-2 ansible_ssh_host=10.128.0.3 ip=10.128.0.3 etcd_member_name=etcd2
instance-3 ansible_ssh_host=10.128.0.4 ip=10.128.0.4 etcd_member_name=etcd3
instance-4 ansible_ssh_host=10.128.0.5 ip=10.128.0.5
instance-5 ansible_ssh_host=10.150.0.2 ip=10.150.0.2

# Master Node
[kube-master]
instance-1
instance-2
instance-3

# Etcd Node where Kube's Cluster Data will be saved
[etcd]
instance-1
instance-2
instance-3

# Worker Node
[kube-node]
instance-4
instance-5

[calico-rr]

# Node where Kube will be installed
# As a default, every node except etcd node will be assigned
[k8s-cluster:children]
kube-master
kube-node
calico-rr

 

모든 설치가 완료되었다면 Root로 들어가 노드정보를 한번 확인해 보자

  • sudo -i
  • kubectl get node
  • 모든 Node의 STATUS가 Ready라면 준비 끝
NAME         STATUS   ROLES    AGE     VERSION
instance-1   Ready    master   6m58s   v1.18.3
instance-2   Ready    master   6m12s   v1.18.3
instance-3   Ready    master   6m12s   v1.18.3
instance-4   Ready    <none>   5m13s   v1.18.3
instance-5   Ready    <none>   5m13s   v1.18.3