Docker 설치
apt 저장소를 사용하여 설치
새 호스트 시스템에 처음으로 Docker 엔진을 설치하기 전에 Docker 리포지토리를 설정해야 합니다. 그런 다음 리포지토리에서 Docker를 설치하고 업데이트할 수 있습니다.
저장소 설정
HTTPS를 통해 리포지토리를 사용할 수 있도록 패키지 인덱스를 업데이트 apt하고 패키지를 설치합니다 .
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
Docker의 공식 GPG 키를 추가합니다.
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
다음 명령을 사용하여 리포지토리를 설정합니다.
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
도커 엔진 설치
패키지 색인을 업데이트합니다.
sudo apt-get update
Docker Engine, containerd 및 Docker Compose를 설치합니다.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
설치완료!
도커 버전을 확인합니다.
sudo docker version
명령어 모음
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker version
쿠버네티스 설치
그리고 보안그룹으로 들어가 해당 포트들을 열어줘야 합니다.
Protocol | Direction | Port Range | Purpose | User BY |
TCP | Inbount | 6443 | Kubernetes API | ALL |
TCP | Inbount | 2379 - 2380 | etcd server client API | kubu-apiserver,etcd |
TCP | Inbount | 10250 | Kubelet API | self,Control plane |
TCP | Inbount | 10259 | kubu-scheduler | self |
TCP | Inbount | 10257 | kube-controller-manager | self |
kubeadm, kubelet 및 kubectl 설치
- kubeadm: 클러스터를 부트스트랩하는 명령입니다.
- kubelet: 클러스터의 모든 시스템에서 실행되고 포드 및 컨테이너 시작과 같은 작업을 수행하는 구성 요소입니다.
- kubectl: 클러스터와 대화하기 위한 명령줄 유틸리티입니다.
공통 설치 master & worker
우선 시작하기전에 swap이 비활성화 되어있어야 합니다.
sudo swapoff -a
1. 패키지 인덱스를 업데이트 apt하고 Kubernetes apt리포지토리를 사용하는 데 필요한 패키지를 설치합니다.
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
2. Google Cloud 공개 서명 키를 다운로드합니다.
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
3. Kubernetes apt 리포지토리를 추가합니다.
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
4. 패키지 인덱스를 업데이트하고 aptkubelet, kubeadm 및 kubectl을 설치하고 해당 버전을 고정합니다.
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
systemctl start kubelet && systemctl enable kubelet
//sudo apt-get update 명령어 오류시
sudo apt-get install -y curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
5. systemd 와 cgroup 설정 맞추기 --- 꼭 해야합니다!!! 중요!!!
sudo mkdir /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
6. 재시작 필수
sudo systemctl enable docker
sudo systemctl daemon-reload
sudo systemctl restart docker
마스터 설정 (마스터 노드에서만 진행!)
여기서부터는 꼭 마스터 노드에서만 진행해야합니다.!!
5. 컨트롤 플레인 노드를 초기화
sudo kubeadm init
1-1. control plane에서 kubeadm init 입력 시 에러 (5번) 났다면 아래 명령어를 참고해주세요.
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
sudo kubeadm init
kubeadm init 명령어를 치면 해당 로그들이 뜬다
ubuntu@ip-172-31-51-94:~$ sudo kubeadm init
[init] Using Kubernetes version: v1.27.2
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
W0518 08:36:11.678436 2631 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.2, falling back to the nearest etcd version (3.5.7-0)
W0518 08:36:26.625265 2631 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image.
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [ip-172-31-51-94 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.31.51.94]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [ip-172-31-51-94 localhost] and IPs [172.31.51.94 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [ip-172-31-51-94 localhost] and IPs [172.31.51.94 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
W0518 08:36:43.204745 2631 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.2, falling back to the nearest etcd version (3.5.7-0)
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 9.501489 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node ip-172-31-51-94 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node ip-172-31-51-94 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: za3h0k.nubrjvxbh3pnlw9u
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
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 172.31.51.94:6443 --token za3h0k.nubrjvxbh3pnlw9u \
--discovery-token-ca-cert-hash sha256:7458f938e49cb14d9a0baa88fc265eb2164001ae7fba5a5915cea82e4ec9d1b4
kubeadm init 명령어를 사용하면 나오는 해당 부분의 명령어들을 사용할 것 입니다.
그리고 마지막에 나오는 토큰은 워커노드와 join하는데 필요하므로 꼭 저장해줘야 합니다.
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
마스터 only flannel 설치 - 쿠버네티스 네트워크 플러그인
쿠버네티스에서 노드와 마스터의 통신을 위한 가상 네트워크를 자동으로 잡아주고 설정해주는 플러그인 입니다
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
상태확인
control plane 노드의 상태가 stanby인지 확인합니다.
kubectl get nodes
Worker Node 구성 : 워커노드에서만 진행
kubeadm join 을 사용하여 워커 노드를 master 에 조인시킵니다. 이때 필요한 네트워크 설정은 flannel 이 잡아주게 됩니다.
sudo kubeadm join 172.31.51.94:6443 --token za3h0k.nubrjvxbh3pnlw9u --discovery-token-ca-cert-hash sha256:7458f938e49cb14d9a0baa88fc265eb2164 001ae7fba5a5915cea82e4ec9d1b4
워커노드 조인 시 [ERROR CRI]: container runtime is not running 에러가 발생하는 경우
/etc/containerd/config.toml 파일에서
disabled_plugins 항목에서 CRI 제거한 뒤 혹은 주석처리 한 뒤
sudo systemctl restart containerd
이렇게 마스터노드랑 워커노드가 조인되었습니다.
참고자료
'쿠버네티스' 카테고리의 다른 글
Kubernetes Engine에서 Jenkins로 지속적 배포 (0) | 2023.05.12 |
---|---|
Kubernetes Engine으로 배포 관리 (0) | 2023.05.12 |
Kubernetes를 통한 클라우드 조정 (0) | 2023.05.12 |
Kubernetes Engine: Qwik Start (0) | 2023.05.12 |
Docker (0) | 2023.05.08 |