반응형

vm 구성

hostname ip  os version
master 192.168.79.140 centos 7.9. 2009
node1 192.168.79.141 centos 7.9. 2009
node2 192.168.79.142 centos 7.9. 2009

 

Master node, Work node 최소 사양

Master node 최소 사양 : CPU: 2 Core, RAM: 2G

Worker node 최소 사양 : CPU: 1 Core, RAM: 1G



출처: https://ikcoo.tistory.com/9 [이쿠의 슬기로운 개발생활]

 

1. 각 노드 별 패키지 업데이트

 yum -y update

 

 

2. 도커 설치 및 실행

2.1 필요 패키지들을 설치해준다.

 yum install -y yum-utils  device-mapper-persistent-data  lvm2

 

 

2.2 방화벽 disable

 systemctl stop firewalld && systemctl disable firewalld

 

2.3 repository 등록

 yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

 

2.4 도커 설치

 yum install -y docker-ce docker-ce-cli containerd.io

 

 2.5 서비스 실행

 systemctl enable docker && systemctl start docker 

 

 

 2.6 서비스 실행 확인

ps -ef | grep docker
root      74290      1  0 14:36 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root      74430  17689  0 14:49 pts/0    00:00:00 grep --color=auto docker

 

2.7 컨테이너 런타임 설정

cat << END  > /etc/docker/daemon.json
{
 "exec-opts": ["native.cgroupdriver=systemd"],
 "log-driver": "json-file",
 "log-opts": {
   "max-size": "100m"
 },
 "storage-driver": "overlay2"
}
END

 

3. 쿠버네티스 설치

 

3.1 swap disabled 스왑은 반드시 off로 해야한다.

swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab

 

3.2 Letting iptables see bridged traffic 

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sudo sysctl --system

 

3.3 kubeadm. kubectl installation

cat <<EOF |  tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg 
exclude=kubelet kubeadm kubectl
EOF
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet

 

3.4 selinux 종료

setenforce 0

sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

 

3.5 kubeadm init (master에서 적용)

kubeadm init 

아래부분 빨간 명령어부터 sha256값 까지 복사해두자

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.79.140:6443 --token 1qcrc2.uyvrm8gzrtfth3nv \
        --discovery-token-ca-cert-hash sha256:626ed4ec6ec3b829c992c7eb9b9106f6f20ba61d02fb8b410cb28d2f8e1ec1e2 

 

3.6 master node에서 kubectl 명령을 쓸 수 있도록 허용 ( master에서 적용)

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

 

3.7 CNI - Weave 적용 (master에서 적용)

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

 

3.8 master 확인

 kubectl get nodes
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   9m42s   v1.21.1

 

3.9 나머지 node 적용

아까 복사해두었던 해쉬값을 노드에 적용

kubeadm join 192.168.79.140:6443 --token 1qcrc2.uyvrm8gzrtfth3nv \
        --discovery-token-ca-cert-hash sha256:626ed4ec6ec3b829c992c7eb9b9106f6f20ba61d02fb8b410cb28d2f8e1ec1e2 

 

3.10 확인 master에서 실행

kubectl get nodes

* 쿠버네티스 자동완성 적용

*.1 bash_complete 설치

yum -y install bash_completion

 

*.2 bash쉘에 영구적으로 추가

source <(kubectl completion bash) 
echo "source <(kubectl completion bash)" >> ~/.bashrc

 

*.3 kubectl을 k로 alias 적용

alias k=kubectl
complete -F __start_kubectl k

참조 url : https://kubernetes.io/ko/docs/reference/kubectl/cheatsheet/

반응형

+ Recent posts