본문 바로가기
Linux/Kubernetes

Kubernetes install in CentOS 7.8

by Miners1205 2023. 8. 10.
반응형

* Kubernetes Install in CentOS 7.8

- 서버 구성

Name IP Role
master 10.0.0.5 master
worker 10.0.0.4 worker

 

OS 설정
### hosts 등록
$ vim /etc/hosts
10.0.0.8 master
10.0.0.4 worker

### Selinux 비활성화
$ vim /etc/selinux/config
SELINUX=disabled

### 방화벽 중지
$ systemctl stop firewalld
$ systemctl disable firewalld

### Swap 메모리 OFF
$ swapoff -a

### 커널 설정 변경
$ yum install bash-completion rsync git vim net-tools tree bridge-utils

$ echo "vm.swappiness=1" >> /etc/sysctl.d/docker.conf

$ echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/docker.conf

$ sysctl -w vm.swappiness=1
$ sysctl -w net.ipv4.ip_forward=1

$ vim  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

$ sysctl --system

 

Docker 설치
$  yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum -y install docker-ce docker-ce-cli containerd.io
$ mkdir -p /etc/docker/
$ cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

$ systemctl daemon-reload
$ systemctl enable docker
$ systemctl start docker
$ systemctl start docker && systemctl enable docker

 

Kubernetes 설치 준비
$ vim /etc/yum.repos.d/kubernetes.repo

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl

또는 

[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

### 2022.05.19 업데이트
sudo bash -c 'cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
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=kube*
EOF'
###

$ yum repolist

### 최신 버전 설치시 하단 명령어
$ yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

$ systemctl enable kubelet && systemctl start kubelet

 

Master, Worker 노드 설치

 

### Master 노드 ###
### ip는 해당 내부 IP
$ kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.0.5
....
kubeadm join 10.0.0.5:6443 --token 4cbvqr.btjrgtfqyj649jtl \ --discovery-token-ca-cert-hash sha256:4fb93a143d8a5cc5c755a62f04d1d40332abfe7684b057e789007b9b5adebdf0

### 위 명령시 아래와 같은 에러 발생시 조치사항 ###
[init] Using Kubernetes version: v1.24.0 [preflight] Running pre-flight checks error execution phase preflight: [preflight] Some fatal errors occurred: [ERROR CRI]: container runtime is not running: output: time="2022-05-19T15:53:31+09:00" level=fatal msg="getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService" , error: exit status 1 [preflight] If you know what you are doing, you can make a check non-fatal with
--ignore-preflight-errors=...
To see the stack trace of this error execute with --v=5 or higher

$ rm -rf /etc/containerd/  
$ reboot
### 위 폴더 삭제 이후 서버 모두 재부팅


### 위 내용을 Worker 노드에 설치해야하니 복사
### Worker 노드
$ kubeadm join 10.0.0.5:6443 --token 4cbvqr.btjrgtfqyj649jtl \ --discovery-token-ca-cert-hash sha256:4fb93a143d8a5cc5c755a62f04d1d40332abfe7684b057e789007b9b5adebdf0

### Master 노드
$ export KUBECONFIG=/etc/kubernetes/admin.conf

### Master 노드
### CNI Flannel 설치 
$ kubectl apply -f 
https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

 

마스터 실행 확인
$ kubectl get pods --all-namespaces

 

 

 

 

 

Node NotReady 이슈

 

o 위 그림처럼 Pending 및 Not Ready 이슈시 하단 내용 확인

o Kubernets Not Ready & Coredns Pending 이슈 확인

o kube-flannel.yaml 적용
$ kubectl edit cm corends -n kube-system 
-> 하단 24번줄 loop 주석처리 및 저장

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

24줄 주서처리

o 이후 coredns 서비스 정상 작동 확인 완료 및 NotReady -> Ready 변경 확인

Running 상태 확인
Ready 상태 확인

 

반응형

'Linux > Kubernetes' 카테고리의 다른 글

Kubernetes Apache Web Test  (0) 2023.08.10