Kubernetes Calico CNI 설치하기

Kubernetes 네트워킹: Calico CNI 설치하기 🚀

소개 🌟

안녕하세요! 오늘은 Kubernetes 클러스터에 Calico CNI(Container Network Interface)를 설치하는 과정을 상세히 알아보겠습니다. Calico는 Kubernetes의 대표적인 네트워크 솔루션으로, 확장성과 성능이 뛰어나 많은 기업 환경에서 사용되고 있습니다.

Calico란? 🤔

Calico는 컨테이너, 가상 머신, 호스트 기반 워크로드에 안전한 네트워크 연결을 제공하는 오픈소스 네트워킹 및 보안 솔루션입니다. Kubernetes에서는 CNI 플러그인으로 사용되어 Pod 간의 네트워크 통신을 담당합니다.

주요 기능:

  • Pod 간 네트워크 통신
  • 네트워크 정책을 통한 세분화된 접근 제어
  • BGP 라우팅을 통한 효율적인 네트워크 구성
  • 네트워크 보안 강화

사전 요구사항 📋

  • 실행 중인 Kubernetes 클러스터
  • kubectl 명령어 액세스
  • 클러스터 관리자 권한

Calico 설치 과정 🛠️

1. 설치 파일 준비 및 VM으로 전송하기

Vagrant VM 환경에서는 파일을 호스트에서 VM으로 전송하는 과정이 필요합니다. 여러 방법이 있지만, 다음과 같은 방법을 사용할 수 있습니다.

첫 번째 방법은 scp 명령을 사용하여 직접 파일을 전송하는 것입니다:

scp calico.yaml [email protected]:/home/vagrant/

이 경우 비밀번호를 요구하는데, Vagrant VM의 기본 비밀번호는 vagrant입니다:

[email protected]'s password: vagrant

또는 SSH 키를 지정하여 SCP 명령을 사용할 수 있습니다:

scp -i .vagrant/machines/k8s-master/virtualbox/private_key calico.yaml [email protected]:/home/vagrant/

여러 파일을 한번에 전송하려면:

scp calico.yml nginx-ingress.yml cert-manager.yml letsencrypt-issuer.yml api-ingress.yml [email protected]:/home/vagrant/

또는 vagrant scp 플러그인을 사용할 수도 있습니다. 먼저 플러그인을 설치해야 합니다:

vagrant plugin install vagrant-scp

그런 다음 파일을 VM으로 전송합니다:

vagrant scp calico.yaml k8s-master:/home/vagrant/

2. Pod 네트워크 CIDR 확인하기

Calico를 설치하기 전에 클러스터가 어떤 Pod 네트워크 CIDR을 사용하는지 확인해야 합니다. 일반적으로 이 값은 kubeadm init 명령의 --pod-network-cidr 옵션으로 설정됩니다.

# 마스터 노드 설정 스크립트 확인
cat master_setup.yml

# 예시 출력
# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.56.10

우리 클러스터는 10.244.0.0/16을 Pod 네트워크 CIDR로 사용하고 있네요!

3. CIDR 값 수정하기

다운로드한 매니페스트 파일에서 CIDR 값을 클러스터 설정과 맞게 수정해야 합니다:

# CALICO_IPV4POOL_CIDR 값 찾기
vim calico.yaml

이 부분을 찾아서:

# The default IPv4 pool to create on startup if none exists. Pod IPs will be
# chosen from this range. Changing this value after installation will have
# no effect. This should fall within `--cluster-cidr`.
# - name: CALICO_IPV4POOL_CIDR
#   value: "192.168.0.0/16"

다음과 같이 수정합니다:

# The default IPv4 pool to create on startup if none exists. Pod IPs will be
# chosen from this range. Changing this value after installation will have
# no effect. This should fall within `--cluster-cidr`.
- name: CALICO_IPV4POOL_CIDR
  value: "10.244.0.0/16"

4. Calico 설치하기

수정한 매니페스트를 적용합니다:

kubectl apply -f calico.yaml

5. 설치 확인하기

Calico 구성 요소가 모두 정상적으로 실행 중인지 확인합니다:

kubectl get pods -n kube-system -l k8s-app=calico-node
kubectl get pods -n kube-system -l k8s-app=calico-kube-controllers

모든 Pod가 ‘Running’ 상태가 될 때까지 기다립니다:

NAME                READY   STATUS    RESTARTS   AGE
calico-node-2zkjp   1/1     Running   0          5m
calico-node-5xnrx   1/1     Running   2          40h

NAME                                       READY   STATUS    RESTARTS   AGE
calico-kube-controllers-7fd98fd54f-mf8hf   1/1     Running   0          5m

문제 해결 🔍

문제 1: 파일 전송 문제

Vagrant VM으로 파일을 전송할 때 다음과 같은 문제가 발생할 수 있습니다:

증상:

  • SCP 명령 사용 시 비밀번호 문제
  • vagrant scp 명령이 동작하지 않음

해결책:

  1. Vagrant의 기본 비밀번호 사용
    # 비밀번호 요청 시 'vagrant' 입력scp calico.yaml [email protected]:/home/vagrant/
    
  2. SSH 키를 지정하여 SCP 사용
    scp -i .vagrant/machines/k8s-master/virtualbox/private_key calico.yaml [email protected]:/home/vagrant/
    
  3. 이미 VM에 접속한 상태라면 다른 방법 사용:
    • 호스트에서 다른 터미널을 열어 파일 전송
    • 공유 폴더 설정하기
    • 내용을 복사하여 VM 내에서 새 파일로 만들기

문제 2: 잘못된 CIDR 설정

제가 경험한 가장 큰 문제는 Calico의 CIDR 설정과 클러스터의 Pod 네트워크 CIDR이 일치하지 않는 경우였습니다.

증상:

  • Pod가 다른 노드의 Pod와 통신할 수 없음
  • Calico Pod가 시작되지만 네트워크 기능이 제대로 작동하지 않음

해결책:

  1. 클러스터가 사용하는 정확한 CIDR 값 확인
  2. Calico 매니페스트의 CIDR 값을 일치시키기
  3. 수정된 매니페스트 다시 적용

문제 3: CRD 문제

때로는 Custom Resource Definition 관련 오류가 발생할 수 있습니다.

증상: 다음과 같은 오류 메시지:

Error from server (BadRequest): error when creating "calico.yml": Installation in version "v1" cannot be handled as a Installation: strict decoding error: unknown field "spec.calicoNetwork"

해결책:

  1. 이전 Calico 설치 제거
    kubectl delete -f calico.yml
    
  2. 최신 공식 매니페스트 다운로드
  3. CIDR 설정 수정 후 다시 설치

문제 4: Calico Pod 초기화 문제

증상:

  • Calico Pod가 Init:0/3 상태에 멈춤
  • ContainerCreating 상태에서 진행이 안 됨

해결책:

  1. Pod의 상세 정보 확인
    kubectl describe pod -n kube-system <calico-pod-name>
    
  2. Pod 로그 확인
    kubectl logs -n kube-system <calico-pod-name> -c init
    
  3. 네트워크나 권한 문제 해결

마무리 🎉

이제 Kubernetes 클러스터에 Calico CNI가 성공적으로 설치되었습니다! 이제 Pod 간 네트워크 통신이 가능하며, 네트워크 정책을 통해 세분화된 접근 제어도 구현할 수 있습니다.

다음 단계로는 MetalLB, Nginx Ingress Controller 등 추가 네트워크 구성 요소를 설치하여 클러스터의 네트워킹 기능을 더욱 확장할 수 있습니다.

궁금한 점이 있거나 추가 도움이 필요하시면 댓글로 남겨주세요! 😊

Installing Calico CNI on Kubernetes: A Comprehensive Guide 🚀

Introduction 🌟

Hello there! Today, we’ll dive into the process of installing Calico CNI (Container Network Interface) on a Kubernetes cluster. Calico is one of the leading networking solutions for Kubernetes, known for its scalability and performance, making it a popular choice in enterprise environments.

What is Calico? 🤔

Calico is an open-source networking and security solution that provides secure network connectivity for containers, virtual machines, and host-based workloads. In Kubernetes, it serves as a CNI plugin responsible for network communication between pods.

Key Features:

  • Pod-to-pod network communication
  • Fine-grained access control through network policies
  • Efficient network configuration via BGP routing
  • Enhanced network security

Prerequisites 📋

  • A running Kubernetes cluster
  • Access to kubectl commands
  • Cluster administrator privileges

Installation Process 🛠️

1. Preparing and Transferring Files to the VM

In a Vagrant VM environment, you’ll need to transfer files from your host to the VM. There are several methods you can use.

The most direct approach is to use the scp command:

scp calico.yaml [email protected]:/home/vagrant/

When prompted for a password, you should enter the default Vagrant password, which is vagrant:

[email protected]'s password: vagrant

Alternatively, you can use SSH key authentication with SCP:

scp -i .vagrant/machines/k8s-master/virtualbox/private_key calico.yaml [email protected]:/home/vagrant/

To transfer multiple files at once:

scp calico.yml nginx-ingress.yml cert-manager.yml letsencrypt-issuer.yml api-ingress.yml [email protected]:/home/vagrant/

You can also use the vagrant scp plugin if you prefer. First, install the plugin:

vagrant plugin install vagrant-scp

Then transfer files to the VM:

vagrant scp calico.yaml k8s-master:/home/vagrant/

2. Verify Pod Network CIDR

Before installing Calico, we need to verify which Pod Network CIDR our cluster is using. This value is typically set using the --pod-network-cidr option in the kubeadm init command.

# Check master node setup script
cat master_setup.yml

# Example output
# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.56.10

Our cluster is using 10.244.0.0/16 as the Pod Network CIDR!

3. Modify the CIDR Value

Edit the downloaded manifest file to match the CIDR value with our cluster configuration:

# Find the CALICO_IPV4POOL_CIDR value
vim calico.yaml

Look for this section:

# The default IPv4 pool to create on startup if none exists. Pod IPs will be
# chosen from this range. Changing this value after installation will have
# no effect. This should fall within `--cluster-cidr`.
# - name: CALICO_IPV4POOL_CIDR
#   value: "192.168.0.0/16"

Modify it to:

# The default IPv4 pool to create on startup if none exists. Pod IPs will be
# chosen from this range. Changing this value after installation will have
# no effect. This should fall within `--cluster-cidr`.
- name: CALICO_IPV4POOL_CIDR
  value: "10.244.0.0/16"

4. Install Calico

Apply the modified manifest:

kubectl apply -f calico.yaml

5. Verify the Installation

Check that all Calico components are running properly:

kubectl get pods -n kube-system -l k8s-app=calico-node
kubectl get pods -n kube-system -l k8s-app=calico-kube-controllers

Wait until all pods show ‘Running’ status:

NAME                READY   STATUS    RESTARTS   AGE
calico-node-2zkjp   1/1     Running   0          5m
calico-node-5xnrx   1/1     Running   2          40h

NAME                                       READY   STATUS    RESTARTS   AGE
calico-kube-controllers-7fd98fd54f-mf8hf   1/1     Running   0          5m

Troubleshooting 🔍

Issue 1: File Transfer Problems

When transferring files to a Vagrant VM, you might encounter these issues:

Symptoms:

  • Password issues when using SCP
  • vagrant scp command doesn’t work

Solution:

  1. Use Vagrant’s default password
    # When prompted for password, enter 'vagrant'scp calico.yaml [email protected]:/home/vagrant/
    
  2. Use SCP with the SSH key specified
    scp -i .vagrant/machines/k8s-master/virtualbox/private_key calico.yaml [email protected]:/home/vagrant/
    
  3. If already logged into the VM, try alternative methods:
    • Open another terminal from the host to transfer files
    • Configure a shared folder
    • Copy content and create a new file within the VM

Issue 2: Incorrect CIDR Configuration

The most significant issue I encountered was when Calico’s CIDR setting didn’t match the cluster’s Pod Network CIDR.

Symptoms:

  • Pods unable to communicate with pods on different nodes
  • Calico pods start but networking functionality doesn’t work properly

Solution:

  1. Verify the exact CIDR value used by your cluster
  2. Match the CIDR value in the Calico manifest
  3. Reapply the modified manifest

Issue 3: CRD Issues

Sometimes, you might encounter Custom Resource Definition related errors.

Symptoms: Error messages like:

Error from server (BadRequest): error when creating "calico.yml": Installation in version "v1" cannot be handled as a Installation: strict decoding error: unknown field "spec.calicoNetwork"

Solution:

  1. Remove previous Calico installation
    kubectl delete -f calico.yml
    
  2. Download the latest official manifest
  3. Modify CIDR settings and reinstall

Issue 4: Calico Pod Initialization Problems

Symptoms:

  • Calico pods stuck in Init:0/3 state
  • Pods stuck in ContainerCreating state

Solution:

  1. Check detailed pod information
    kubectl describe pod -n kube-system <calico-pod-name>
    
  2. Check pod logs
    kubectl logs -n kube-system <calico-pod-name> -c init
    
  3. Address any network or permission issues

Conclusion 🎉

You’ve now successfully installed Calico CNI on your Kubernetes cluster! Pod-to-pod network communication is now enabled, and you can implement fine-grained access control through network policies.

Next steps could include installing additional networking components like MetalLB or Nginx Ingress Controller to further enhance your cluster’s networking capabilities.

If you have any questions or need further assistance, feel free to leave a comment below! 😊

답글 남기기