반응형
Master 1대, Worked 1대로 테스트 구성
Master / Worked 둘다 작업
[docker 설치]
1. 종속성 설치
sudo apt update sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common |
2. GPG 키 가져오기
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
3. docker APT 리포지토리 추가
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
4. docker 설치
apt install docker-ce docker-ce-cli containerd.io |
[kubernetes 설치 전 환경 설정]
1. swapoff
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab |
2. /etc/sysctl.d/k8s.conf 설정, 적용
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 |
3. 방화벽 disable
systemctl stop firewalld systemctl disabled firewalld |
[kubeadm, kubectl, kubelet 설치]
1. apt kubernetes apt 리포지토리를 사용하는데 필수 패키지 설치
apt-get update apt-get install -y apt-transport-https ca-certificates curl |
2. google cloud 공개 서명 키 다운로드
mkdir -p /etc/apt/keyrings curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg |
3. kubernetes apt 리포지토리 추가
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list |
4. kubelet, kubeadm, kubectl 설치
apt-get update apt-get install -y kubelet kubeadm kubectl |
5. version hold
apt-mark hold kubelet kubeadm kubectl |
6. daemon start
systemctl enable kubelet systemctl start kubelet |
Master 작업
1. initialize
kubeadm init |
※ 에러
[preflight] Running pre-flight checks error execution phase preflight: [preflight] Some fatal errors occurred: [ERROR CRI]: container runtime is not running: output: time="2023-07-20T07:02:28Z" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.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 |
※ 해결 방법
vi /etc/containerd/config.toml disabled_plugins = ["cri"] -> enabled_plugins = ["cri"]`
systemctl restart containerd.service |
2. token.txt
kubeadm join [Master node IP]:6443 --token 6jmmvl.io0ayi3r4e88f214 \ --discovery-token-ca-cert-hash sha256:1ad8f40017dffdc58c00f631457bcbe54111fa218c791356852dc330a82c27cb |
※ 에러
kubectl get nodes E0720 07:16:42.376110 16035 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0720 07:16:42.376778 16035 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0720 07:16:42.383078 16035 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0720 07:16:42.383695 16035 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0720 07:16:42.385621 16035 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused The connection to the server localhost:8080 was refused - did you specify the right host or port? |
※ 해결 방법
mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config |
3. Installing a Pod network add-on
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s-1.11.yaml |
Worked node 작업
1. master join 작업(master 에서 initializing 시 join 값 입력)
kubeadm join [Master node IP]:6443 --token 6jmmvl.io0ayi3r4e88f214 \ --discovery-token-ca-cert-hash sha256:1ad8f40017dffdc58c00f631457bcbe54111fa218c791356852dc330a82c27cb |
2. join 확인
※ kubectl 명령어 자동완성
source <(kubectl completion bash) echo "source <(kubectl completion bash)" >> ~/.bashrc |
※ kubeadm 명령어 자동완성
source <(kubeadm completion bash) echo "source <(kubeadm completion bash)" >> ~/.bashrc |
명령어 사용법
(vi 편집기 열어 편집)
kubectl edit deployments.apps mainui |
(nginx 이지미를 yaml 파일로 만들기)
kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml > webserver-pods.ymal |
(pod 파일 vi 편집기로 편집)
kubectl edit deployments.apps mainui |
(pod 삭제)
kubectl delete deployments.apps mainui kubectl delete pod webserver |
(yaml 파일로 pod 실행)
kubectl create -f webserver-pods.ymal |
(pod 생성 및 실행)
kubectl run nginx-webser --image=nginx:1.14 --port 80 |
(pod 삭제)
kubectl delete pods nginx-webser |
반응형