k3s -> fail THEN go k8s

🚀 쿠버네티스 홈랩 구축기: k3s로 겪은 시행착오와 해결책

안녕하세요, 쿠버네티스 입문자 여러분! 오늘은 제가 VirtualBox와 Vagrant를 사용해 k3s 클러스터를 구축하면서 겪은 여러 문제들과 그 해결 과정을 공유하려고 합니다. 처음부터 완벽하게 되는 일은 거의 없죠? 실패를 통해 더 많이 배울 수 있답니다! 😊

🌟 성공적으로 한 것들

먼저 잘 진행된 부분들을 정리해 볼게요:

  1. VirtualBox와 Vagrant를 이용해 마스터 노드와 워커 노드 VM 생성
  2. k3s 설치 및 기본 클러스터 구성
  3. 워커 노드를 마스터 노드에 연결
  4. kubectl 설정 및 기본 명령어 사용
  5. nginx 배포 및 서비스 생성

🔥 문제 발생과 해결 과정

1. Calico 네트워크 플러그인 설치 문제 😓

문제: 처음에 Calico 네트워크 플러그인을 사용하려 했으나, 초기화 과정에서 문제 발생

# 시도한 설치 방법
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --cluster-cidr=192.168.0.0/16" sh -

# Calico 설치
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml

오류 메시지:

Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkPluginNotReady

해결책: 결국 Calico 대신 k3s의 기본 네트워크 플러그인(Flannel)을 사용하기로 결정

# k3s 제거
sudo /usr/local/bin/k3s-uninstall.sh

# 기본 설정으로 재설치
curl -sfL https://get.k3s.io | sh -

2. kubectl 권한 문제 🔒

문제: 일반 사용자로 kubectl 명령 실행 시 권한 오류 발생

error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

해결책: kubeconfig 파일을 사용자 홈 디렉토리에 복사하고 권한 설정

mkdir -p $HOME/.kube
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

3. 서비스 연결 문제 🌐

문제: NodePort 서비스가 생성되었으나 접속이 안 되는 문제

# 서비스 생성
kubectl expose deployment nginx --port=80 --type=NodePort

# 서비스 확인
kubectl get svc nginx
# NAME    TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
# nginx   NodePort   10.43.70.69   <none>        80:30723/TCP   3h41m

문제 확인 과정:

  1. 서비스 IP로 접근 시도 실패: curl 10.43.70.69:80
  2. NodePort로 접근 시도 실패: curl localhost:30723
  3. 팟 IP로 직접 접근은 성공: curl 10.42.1.5:80

원인: k3s의 kube-proxy 설정 또는 네트워크 구현 방식의 차이

해결 방안:

  • LoadBalancer 타입으로 서비스 변경 시도
  • k3s 서비스 재시작
  • 완전히 새로 설치 고려

4. 호스트 PC에서 VM 접근 문제 💻

문제: 호스트 PC에서 VirtualBox VM으로 ping이나 서비스 접속이 안 됨

ping 192.168.56.10
# ping: sendto: No route to host

nc -zv 192.168.56.10 22
# nc: connectx to 192.168.56.10 port 22 (tcp) failed: No route to host

확인 사항:

  1. VirtualBox 호스트 전용 네트워크 설정 확인
  2. VM 네트워크 인터페이스 설정 확인
  3. 호스트 PC의 라우팅 테이블 확인: netstat -nr | grep 192.168.56
  4. VM의 방화벽 규칙 확인: sudo iptables -L INPUT

해결 방안: VirtualBox NAT 어댑터를 통한 포트 포워딩 설정 (호스트 8080 → VM 30723)

🤔 k3s vs 전체 쿠버네티스(k8s)

k3s는 경량 쿠버네티스로 설계되어 있어 전체 쿠버네티스와 차이점이 있습니다:

  1. 리소스 사용량이 적음 (메모리, CPU)
  2. 단일 바이너리로 설치 간편
  3. 자체 네트워크 솔루션 사용 (Flannel 기반)
  4. 일부 컴포넌트가 간소화되거나 다르게 구현됨

이런 차이로 인해 표준 쿠버네티스 환경과 동작이 다를 수 있습니다. 학습 목적이나 실제 프로덕션 환경과 유사한 경험을 원한다면 전체 쿠버네티스(kubeadm으로 설치)가 더 적합할 수 있습니다.

🎓 배운 점

이번 경험을 통해 배운 중요한 교훈들:

  1. 네트워크 플러그인 선택은 신중하게 – 기본 제공되는 것부터 시작하는 것이 안전
  2. 문제 해결 시 단계적 접근이 중요 (Pod → Service → 외부 접속)
  3. 가상 환경에서의 네트워크 설정은 복잡할 수 있으며, 포트 포워딩은 좋은 우회책
  4. k3s와 k8s의 차이점을 이해하고 용도에 맞게 선택해야 함

📝 다음 단계

다음에는 kubeadm을 사용한 전체 쿠버네티스 클러스터 구축을 시도해볼 예정입니다. 더 복잡하지만 실제 프로덕션 환경과 유사한 경험을 제공해 줄 것입니다.

오늘의 시행착오가 여러분의 쿠버네티스 여정에 도움이 되길 바랍니다! 실패를 두려워하지 말고, 그 과정에서 배우는 즐거움을 느껴보세요. 😄

🚀 Kubernetes Home Lab Journey: Trials and Solutions with k3s

Hello, Kubernetes beginners! Today I’d like to share the various challenges I encountered while building a k3s cluster with VirtualBox and Vagrant, along with how I solved them. Nothing works perfectly the first time, right? We learn the most through our failures! 😊

🌟 What Worked Well

Let’s start with what went smoothly:

  1. Creating master and worker node VMs using VirtualBox and Vagrant
  2. Installing k3s and setting up the basic cluster
  3. Connecting the worker node to the master node
  4. Configuring kubectl and using basic commands
  5. Deploying nginx and creating a service

🔥 Challenges and Solutions

1. Calico Network Plugin Installation Issues 😓

Problem: Initially tried to use the Calico network plugin, but encountered issues during initialization

# Installation attempt
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --cluster-cidr=192.168.0.0/16" sh -

# Calico installation
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml

Error Message:

Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkPluginNotReady

Solution: Eventually decided to use k3s’s default network plugin (Flannel) instead of Calico

# Remove k3s
sudo /usr/local/bin/k3s-uninstall.sh

# Reinstall with default settings
curl -sfL https://get.k3s.io | sh -

2. kubectl Permission Issues 🔒

Problem: Permission errors when trying to run kubectl commands as a regular user

error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

Solution: Copy the kubeconfig file to the user’s home directory and set proper permissions

mkdir -p $HOME/.kube
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

3. Service Connection Issues 🌐

Problem: NodePort service was created but couldn’t connect to it

# Creating the service
kubectl expose deployment nginx --port=80 --type=NodePort

# Checking the service
kubectl get svc nginx
# NAME    TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
# nginx   NodePort   10.43.70.69   <none>        80:30723/TCP   3h41m

Troubleshooting Process:

  1. Failed to access via service IP: curl 10.43.70.69:80
  2. Failed to access via NodePort: curl localhost:30723
  3. Successfully accessed via pod IP directly: curl 10.42.1.5:80

Root Cause: Issues with k3s’s kube-proxy configuration or differences in network implementation

Possible Solutions:

  • Try changing service type to LoadBalancer
  • Restart k3s service
  • Consider a complete reinstallation

4. Host PC to VM Access Issues 💻

Problem: Unable to ping or connect to services from the host PC to the VirtualBox VM

ping 192.168.56.10
# ping: sendto: No route to host

nc -zv 192.168.56.10 22
# nc: connectx to 192.168.56.10 port 22 (tcp) failed: No route to host

Verification Steps:

  1. Checked VirtualBox host-only network settings
  2. Verified VM network interface configuration
  3. Examined host PC routing table: netstat -nr | grep 192.168.56
  4. Checked VM firewall rules: sudo iptables -L INPUT

Solution: Configure port forwarding through the VirtualBox NAT adapter (host 8080 → VM 30723)

🤔 k3s vs Full Kubernetes (k8s)

k3s is designed as a lightweight Kubernetes distribution, so it has some differences from full Kubernetes:

  1. Lower resource usage (memory, CPU)
  2. Simpler installation with a single binary
  3. Uses its own network solution (based on Flannel)
  4. Some components are simplified or implemented differently

These differences can lead to behavior that varies from a standard Kubernetes environment. If you’re learning or want an experience similar to a production environment, full Kubernetes (installed with kubeadm) might be more appropriate.

🎓 Lessons Learned

Important lessons from this experience:

  1. Choose network plugins carefully – starting with the default one is often safer
  2. Take a step-by-step approach to troubleshooting (Pod → Service → External access)
  3. Network configuration in virtual environments can be complex; port forwarding is a good workaround
  4. Understand the differences between k3s and k8s and choose based on your needs

📝 Next Steps

Next, I plan to attempt building a full Kubernetes cluster using kubeadm. It will be more complex but will provide an experience more similar to actual production environments.

I hope today’s trials and errors help you on your Kubernetes journey! Don’t be afraid of failures; enjoy the learning process along the way. 😄

답글 남기기