Kubernetes 네트워킹 인프라 구축(feat.helm)

Kubernetes 네트워킹 인프라 구성: 문제 해결과 자동화 🚀

들어가며 👋

안녕하세요! 오늘은 Kubernetes 클러스터의 네트워킹 인프라 구성에 대한 경험을 공유하려고 합니다. Vagrant와 VirtualBox로 구성한 로컬 Kubernetes 클러스터에 Calico, MetalLB, Nginx Ingress Controller, cert-manager를 설치하는 과정에서 발생한 문제들과 그 해결 방법, 그리고 Helm을 통한 자동화에 대해 알아보겠습니다.

Helm이란? 🌟

먼저 이번에 새롭게 등장한 Helm에 대해 간략히 소개하겠습니다. Helm은 Kubernetes 패키지 관리자로, 복잡한 Kubernetes 애플리케이션을 배포하고 관리하기 위한 도구입니다. 마치 리눅스의 apt나 yum처럼 Kubernetes에서 패키지를 설치, 업그레이드, 제거할 수 있게 해줍니다.

Helm의 주요 개념:

  • Chart: 패키지화된 Kubernetes 리소스 모음
  • Repository: Chart를 저장하고 공유하는 저장소
  • Release: 클러스터에 배포된 Chart의 인스턴스

Helm을 사용하면 여러 복잡한 구성 요소들을 하나의 명령으로 설치할 수 있어, 네트워킹 인프라 구성이 훨씬 쉬워집니다.

네트워킹 인프라 구성 순서 🔄

Kubernetes 네트워킹 인프라는 다음과 같은 순서로 구성됩니다:

  1. Kubernetes 클러스터 초기화
  2. Calico CNI 설치 (Pod 간 네트워크 통신)
  3. MetalLB 설치 (LoadBalancer 서비스 지원)
  4. Nginx Ingress Controller 설치 (외부 HTTP 트래픽 관리)
  5. cert-manager 설치 (TLS 인증서 자동화)
  6. Let’s Encrypt Issuer 설정 (무료 TLS 인증서 발급)

각 구성 요소는 이전 구성 요소에 의존하기 때문에 설치 순서가 중요합니다.

문제와 해결 방법 🛠️

1. Calico CNI 설치 문제

문제: CIDR 설정 불일치

  • Kubernetes 클러스터가 --pod-network-cidr=10.244.0.0/16으로 초기화되었지만, Calico 기본 설정은 192.168.0.0/16을 사용
  • 이로 인해 Pod 네트워크가 제대로 작동하지 않음

해결 방법:

  • Calico 매니페스트 파일에서 CIDR 값을 10.244.0.0/16으로 수정
  • CALICO_IPV4POOL_CIDR 환경 변수를 주석 해제하고 값 변경

2. MetalLB 설치 문제

문제: CRD(Custom Resource Definition) 설치가 분리되어 있음

  • MetalLB 구성 파일(IPAddressPool, L2Advertisement)을 적용하려 했지만 실패
  • no matches for kind "IPAddressPool" in version "metallb.io/v1beta1" 오류 발생

해결 방법:

  • 먼저 MetalLB 컨트롤러와 CRD를 설치
    kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.3/config/manifests/metallb-native.yaml
    
  • 설치가 완료된 후 MetalLB 구성 파일 적용

3. Nginx Ingress Controller 설치 문제

문제: 잘못된 매니페스트 형식

  • 제공된 매니페스트 파일이 HelmChart 커스텀 리소스를 사용
  • 이 형식은 Flux CD나 다른 GitOps 도구용이지만, 일반 Kubernetes에서는 지원하지 않음
  • no matches for kind "HelmChart" in version "helm.sh/v1" 오류 발생

해결 방법:

  • Helm을 설치하고 Helm 차트를 통해 Nginx Ingress Controller 설치
    helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace
    

4. cert-manager 설치 문제

문제: 역시 잘못된 매니페스트 형식

  • cert-manager 설정 파일도 HelmChart 커스텀 리소스 사용
  • 직접 kubectl apply로 적용할 수 없음

해결 방법:

  • Helm을 통해 cert-manager 설치
    helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.12.0 --set installCRDs=true
    
  • 설치 후 Let’s Encrypt Issuer 설정 파일은 일반 Kubernetes 리소스이므로 kubectl apply로 직접 적용 가능

Helm과 Ansible을 통한 자동화 🤖

이런 복잡한 설치 과정을 자동화하기 위해 Helm과 Ansible을 함께 사용할 수 있습니다.

Ansible 플레이북에서:

  1. Helm 설치
  2. 필요한 Helm 리포지토리 추가
  3. 각 구성 요소를 순서대로 Helm으로 설치
  4. 필요한 구성 파일 생성 및 적용

이러한 자동화를 통해 전체 네트워킹 인프라를 일관되게 구성할 수 있으며, 새 클러스터를 빠르게 설정할 수 있습니다.

주요 교훈 💡

  1. 의존성 파악하기: 각 구성 요소의 의존성과 올바른 설치 순서를 이해하는 것이 중요합니다.
  2. CRD 먼저 설치하기: 커스텀 리소스를 사용하기 전에 관련 CRD가 설치되어 있는지 확인해야 합니다.
  3. 매니페스트 형식 확인하기: 사용 중인 매니페스트 파일이 어떤 도구를 위한 것인지 확인하고, 필요에 맞게 사용하세요.
  4. Helm 활용하기: 복잡한 애플리케이션은 Helm을 통해 설치하면 훨씬 간편합니다.
  5. 자동화 구축하기: Ansible 같은 도구로 전체 과정을 자동화하면 오류 가능성을 줄이고 반복 작업을 피할 수 있습니다.

마치며 🎉

Kubernetes 네트워킹 인프라 구성은 복잡할 수 있지만, 문제를 이해하고 올바른 도구와 접근 방식을 사용하면 훨씬 쉬워집니다. 특히 Helm과 Ansible을 활용한 자동화는 이러한 복잡성을 크게 줄여줍니다.

여러분도 이 글을 통해 Kubernetes 네트워킹 인프라를 구성할 때 발생할 수 있는 문제들에 대비하고, 더 효율적으로 작업할 수 있길 바랍니다!

질문이나 의견이 있으시면 언제든지 댓글로 남겨주세요. 감사합니다! 😊

Setting Up Kubernetes Networking Infrastructure: Troubleshooting and Automation 🚀

Introduction 👋

Hello there! Today I want to share my experience setting up networking infrastructure on a Kubernetes cluster. I’ll walk you through the challenges I faced while installing Calico, MetalLB, Nginx Ingress Controller, and cert-manager on a local Kubernetes cluster built with Vagrant and VirtualBox, along with solutions and how to automate everything using Helm.

What is Helm? 🌟

Let me first introduce Helm, a key tool in our setup. Helm is essentially a package manager for Kubernetes, making it easy to deploy and manage complex applications. Think of it as apt or yum for Kubernetes, allowing you to install, upgrade, and remove packages with simple commands.

Key Helm Concepts:

  • Chart: A packaged collection of Kubernetes resources
  • Repository: A storage location for sharing and storing charts
  • Release: An instance of a chart deployed in a cluster

With Helm, you can install complex components with a single command, which greatly simplifies networking infrastructure setup.

Networking Infrastructure Setup Order 🔄

Kubernetes networking infrastructure should be set up in the following order:

  1. Initialize Kubernetes Cluster
  2. Install Calico CNI (for pod-to-pod communication)
  3. Install MetalLB (for LoadBalancer service support)
  4. Install Nginx Ingress Controller (for managing external HTTP traffic)
  5. Install cert-manager (for TLS certificate automation)
  6. Configure Let’s Encrypt Issuer (for free TLS certificates)

Each component depends on the previous one, so the order of installation is crucial.

Problems and Solutions 🛠️

1. Calico CNI Installation Issues

Problem: CIDR Configuration Mismatch

  • Kubernetes cluster was initialized with --pod-network-cidr=10.244.0.0/16, but Calico’s default setting uses 192.168.0.0/16
  • This caused pod networking to not function properly

Solution:

  • Modified the Calico manifest file to use CIDR 10.244.0.0/16
  • Uncommented the CALICO_IPV4POOL_CIDR environment variable and changed its value

2. MetalLB Installation Issues

Problem: Separate CRD (Custom Resource Definition) Installation

  • Tried to apply MetalLB configuration files (IPAddressPool, L2Advertisement) but failed
  • Got the error no matches for kind "IPAddressPool" in version "metallb.io/v1beta1"

Solution:

  • First install the MetalLB controller and CRDs:
    kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.3/config/manifests/metallb-native.yaml
    
  • Then apply the MetalLB configuration files after the installation was complete

3. Nginx Ingress Controller Installation Issues

Problem: Incorrect Manifest Format

  • The provided manifest file used a HelmChart custom resource
  • This format is meant for Flux CD or other GitOps tools, not for direct application in regular Kubernetes
  • Got the error no matches for kind "HelmChart" in version "helm.sh/v1"

Solution:

  • Installed Helm and used it to install the Nginx Ingress Controller
    helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace
    

4. cert-manager Installation Issues

Problem: Again, Incorrect Manifest Format

  • The cert-manager configuration file also used the HelmChart custom resource
  • Couldn’t apply it directly with kubectl

Solution:

  • Used Helm to install cert-manager
    helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.12.0 --set installCRDs=true
    
  • After installation, the Let’s Encrypt Issuer configuration file was a regular Kubernetes resource, so it could be applied directly with kubectl

Automation with Helm and Ansible 🤖

To automate this complex installation process, we can combine Helm and Ansible.

In the Ansible playbook:

  1. Install Helm
  2. Add necessary Helm repositories
  3. Install each component in order using Helm
  4. Create and apply the necessary configuration files

This automation allows you to consistently set up the entire networking infrastructure and quickly configure new clusters.

Key Takeaways 💡

  1. Understand Dependencies: It’s important to understand the dependencies between components and the correct order of installation.
  2. Install CRDs First: Always check if the related CRDs are installed before using custom resources.
  3. Check Manifest Formats: Verify what tools your manifest files are designed for and use them accordingly.
  4. Leverage Helm: Complex applications are much easier to install through Helm.
  5. Build Automation: Automate the entire process with tools like Ansible to reduce the chance of errors and avoid repetitive work.

Conclusion 🎉

Setting up Kubernetes networking infrastructure can be complex, but understanding the problems and using the right tools and approaches makes it much easier. In particular, automation with Helm and Ansible significantly reduces this complexity.

I hope this post helps you prepare for potential issues when setting up your Kubernetes networking infrastructure and work more efficiently!

If you have any questions or comments, feel free to leave them below. Thank you! 😊

답글 남기기