클라우드 엔지니어 꿈나무
Kubernetes 설치 - Centos 7 본문
-master
#! /bin/bash
yum install -y rdate
rdate -s time.bora.net
# selinux off
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
# firewall off & disable
systemctl stop firewalld
systemctl disable firewalld
# Masteer
# firewall-cmd --add-port={80,443,6443,2379,2380,10250,10251,10252,30000-32767}/tcp --permanent
# Node
# firewall-cmd --add-port={80,443,10250,30000-32767}/tcp --permanent
# swap off
swapoff -a
sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab
# overlay 및 iptables Module Load
cat > /etc/modules-load.d/k8s.conf << EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
# iptables 및 NAT 활성화
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward =1
EOF
sysctl --system
# /etc/hosts file edit
cat >> /etc/hosts << EOF
10.0.0.1 master k8s-ma
10.0.0.2 node1 k8s-no1
10.0.0.3 node2 k8s-no2
EOF
# K8S Repository
cat > /etc/yum.repos.d/k8s.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
#gpgcheck=1
#repo_gpgcheck=0
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
# kubeadm, kubelet, kubectl Package Install
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet
systemctl start kubelet
# container runtime install
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y containerd.io
mkdir -p /etc/cotainerd
containerd config default | sudo tee /etc/containerd/config.toml
sed -i'' -r -e "/containerd.default_runtime.options/a\SystemdCgroup=true" /etc/containerd/config.toml
systemctl enable containerd
systemctl restart containerd
# master
#kubeadm config print init-defaults > kubeadm-init.yaml
#cat >> kubeadm-init.yaml << EOF
#---
#apiVersion: kubelet.config.k8s.io/v1beta1
#kind: KubeletConfiguration
#cgroupDriver: systemd
#EOF
#sed -i 's/name: node/name: master/g' kubeadm-init.yaml
#sed -i 's/advertiseAddress: 1.2.3.4/advertiseAddress: 10.0.0.1/' kubeadm-init.yaml
#kubeadm init --config=kubeadm-init.yaml
kubeadm init --ignore-preflight-errors=all --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=10.0.0.1
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
- node 1 & 2
#! /bin/bash
yum install -y rdate
rdate -s time.bora.net
# selinux off
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
# firewall off & disable
systemctl stop firewalld
systemctl disable firewalld
# Masteer
# firewall-cmd --add-port={80,443,6443,2379,2380,10250,10251,10252,30000-32767}/tcp --permanent
# Node
# firewall-cmd --add-port={80,443,10250,30000-32767}/tcp --permanent
# swap off
swapoff -a
sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab
# overlay 및 iptables Module Load
cat > /etc/modules-load.d/k8s.conf << EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
# iptables 및 NAT 활성화
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward =1
EOF
sysctl --system
# /etc/hosts file edit
cat >> /etc/hosts << EOF
10.0.0.1 master k8s-ma
10.0.0.2 node1 k8s-no1
10.0.0.3 node2 k8s-no2
EOF
# K8S Repository
cat > /etc/yum.repos.d/k8s.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
#gpgcheck=1
#repo_gpgcheck=0
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
# kubeadm, kubelet, kubectl Package Install
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet
systemctl start kubelet
# container runtime install
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y containerd.io
mkdir -p /etc/cotainerd
containerd config default | sudo tee /etc/containerd/config.toml
sed -i'' -r -e "/containerd.default_runtime.options/a\SystemdCgroup=true" /etc/containerd/config.toml
systemctl enable containerd
systemctl restart containerd
==========================================
docker
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
docker --version
docker pull weaveworks/weave-kube:latest
docker pull weaveworks/weave-npc
docker save -o weave1.tar weaveworks/weave-npc (tar 아카이브)
scp weave1.tar root@10.0.0.1:/root/
scp weave1.tar root@10.0.0.2:/root/
scp weave1.tar root@10.0.0.3:/root/
docker images
master
vi ma.sh
sh ma.sh
상기 명령어 실행 후, 하기 내용을 node1, node2, node3 에 기입해줘야 하므로 중요
(하기는 10.0.0.6 으로 진행하여 10.0.0.6 이지만 구성도처럼 진행될 시, 10.0.0.1로 표시)
wget https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
vi weave-daemonset-k8s.yaml
124, 155, 186 imagePullPolicy 부분 Never 로 변경
ctr -n k8s.io image import we.tar (아카이브 해제)
crictl -r unix:///run/containerd/containerd.sock image ls (이미지 확인)
kubectl apply -f weave-daemonset-k8s.yaml
node 1 & 2
vi no1.sh (no2.sh2)
sh no1.sh (no2.sh)
master 값 입력
ctr -n k8s.io image import weave.tar
확인
kubectl get nodes : 노드 상태 확인
모두 ready로 바뀐 것을 볼 수 있음
kubectl get pods --namespace kube-system : pod 상태 확인
kubectl get pods -n kube-system : kube-system 상태 확인
<참고>
yum install -y bash-completion : kubectl 자동 완성 기능 추가
'kubernetes' 카테고리의 다른 글
Kubernetes(k8s) Deployments - Centos 7 (0) | 2023.09.13 |
---|---|
Kubernetes(k8s) Replicas - Centos (0) | 2023.09.13 |
Kubernetes Labels - Centos7 (0) | 2023.09.13 |
Kubernetes Pods - Centos7 (0) | 2023.09.13 |
Kubernetes Namespace - Centos7 (0) | 2023.09.12 |