#!/bin/bash
# 방화벽 끄기
systemctl stop firewalld
systemctl disable firewalld
# swap 시스템 메모리가 부족할 경우 하드 공간을 활용하여 작업을 도와주는 영역 --> off
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
# Docker 설치
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y
systemctl enable docker --now
mkdir /etc/docker
cat <<EOF | tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl enable docker
systemctl daemon-reload
systemctl restart docker
cat <<EOF | tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
# 브릿지 연결
cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
systemctl enable --now docker && systemctl status docker
#kubeadm 설치
cat <<EOF | sudo 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
# permissive 모드로 SELinux 설정(효과적으로 비활성화)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet-1.21.4-0 kubeadm-1.21.4-0 kubectl-1.21.4-0 --disableexcludes=kubernetes
systemctl enable --now kubelet
# ip전달 값 변경
echo '1' > /proc/sys/net/ipv4/ip_forward
kubeadm init
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
쿠버네티스 설정LINK
쿠버네티스는 인증서로 통신을한다.
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
kubectl를 사용할 사용자 홈에 집어 넣어줘야한다.
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.0.6:6443 --token zwfaf2.dmzbq1dttqx8tckl \
--discovery-token-ca-cert-hash sha256:f80194adee67af701c319ec3fadb36e0e5335203a69a0bc4096ec441c77c6e6c
노드가 사용하기 위해서는 위 명령어를 입력해줘야한다.
워크 노드와 조인하기위해선는 위 토큰을 사용한다.
k8s가 서로 통신을하기위해서는 cni를 통하여 물리네트워크에다 물릴수있나?
cni 설치 링크 link
[root@master ~]# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" # 현재 weavr는 사용 안되는걸로 보임 (23.07.21)
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.apps/weave-net created
구성 후
노드들에게
# 호스트에 접근할 수 있는 토근과 해쉬값 입력
kubeadm join 10.0.0.6:6443 --token zwfaf2.dmzbq1dttqx8tckl \
--discovery-token-ca-cert-hash sha256:f80194adee67af701c319ec3fadb36e0e5335203a69a0bc4096ec441c77c6e6c