Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

Kubernetes(K8S) 설치 - Centos7 본문

kubernetes

Kubernetes(K8S) 설치 - Centos7

새싹싹이 2023. 9. 16. 18:51

구성도

master

vi. sh

#! /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
10.0.0.4	node3	k8s-no3
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

sh ma.sh

위의 명령어를 실행하면 하기의 창 출력, 해당 값을 각각 node 1~ node3까지 입력

 

node 1~3

#! /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
10.0.0.4	node3	k8s-no3
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

 

sh no1.sh (~no3.sh 까지)

kubeadm join 10.0.0.1:6443 --token 489tn3.3hjxe0xbxtp1ohsg \
--discovery-token-ca-cert-hash sha256:d166f378c73ed8fd1cc83bf00e292b09e3d9a2b285a8eebdceeb460d2eabda0

master와 node 조인

 

 

master

kubectl get node 

node 들이 ready 상태인 것을 볼 수 있다.