버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

  • 여러 서비스와 애플리케이션 간의 작업 흐름을 관리합니다.

Ubuntu Repo 이슈

코드 블럭
apt-get clean
rm -rf /var/lib/apt/lists/*
apt-get update -o Acquire::CompressionTypes::Order::=gz

python 설치

코드 블럭
root@cp-k8s:~/ansible# apt install -y python3.10 python3.10-venv
root@cp-k8s:~/ansible# python3.10 -m venv /opt/python3.10-venv
root@cp-k8s:~/ansible# source /opt/python3.10-venv/bin/activate
(python3.10-venv) root@cp-k8s:/opt# pip install ansible

1.2 파일 생성 예제

  • 이해하기 쉽도록 root 패스워드 및 등록을 진행합니다.

코드 블럭
#cat /etc/hosts
192.168.2.10 cp-k8s
192.168.2.101 w1-k8s
192.168.2.102 w2-k8s
192.168.2.103 w3-k8s

cp-k8s에서 ssh-keygen 생성
# ssh-keygen

모든 노드 root 패스워드 설정
root / vagrant

cp-k8s에서 모든 노드의 root로 접근할 수 있도록 등록
# ssh-copy-id root@cp-k8s
# ssh-copy-id root@w1-k8s
# ssh-copy-id root@w2-k8s
# ssh-copy-id root@w3-k8s

(1) 인벤토리 파일 (hosts)

코드 블럭
#cat ~/hosts
[all]
cp-k8s ansible_host=192.168.12.10    
access_ip=192.168.2.10 ip=192.168.2.10
w1-k8s ansible_host=192.168.12.101   access_ip=192.168.2.101 ip=192.168.2.101
w2-k8s ansible_host=192.168.12.102 access_ip=192.168.2.102 ip=192.168.2.102
w3-k8s ansible_host=192.168.12.103 access_ip=192.168.2.103 ip=192.168.2.103

(2) Playbook (file_management.yaml)

코드 블럭
---
- name: Manage files and directories
  hosts: all
  become: yes   #sudo

  tasks:
    - name: Create a directory
      file:
        path: /opt/myapp
        state: directory
        mode: '0755'

    - name: Create a file with specific content
      copy:
        dest: /opt/myapp/config.txt
        content: |
          [settings]
          setting1 = value1
          setting2 = value2

    - name: Ensure a file is absent
      file:
        path: /opt/myapp/old_config.txt
        state: absent

(3) 실행

코드 블럭
apt install ansible 
ansible-playbook -i hosts file_management.yaml

...

2.1 python 및 가상환경 설치

코드 블럭
apt#apt search python3.9
...
apt#apt install -y python3.10 python3.10-venv
python3#python3.10 -m venv /opt/kubespray-2.25-venv

# source /opt/kubespray-2.2325-venv/bin/activate
pip install -U pip pip install -r requirements.txt


2.2 Kubespray 구성

...

  • 코드 블럭mkdir -p /opt/

    kubespray

    -2.23-git cd /opt/kubespray-2.23-git

    kubespray 소스 다운로드

    코드 블럭
    git clone https://github.com/kubernetes-sigs/kubespray.git -b release-2.23

    디렉토리 이동

    코드 블럭
    25
    cd /opt~/kubespray-2.23-git/kubespray
  • kubespray를 위한 python3 가상환경 구성

    코드 블럭
    python3 -m venv /opt/kubespray-2.23-venv
    source /opt/kubespray-2.23-venv/bin/activate
  • pip 패키지 설치

    코드 블럭
    pip install -U pip
    pip install -r requirements.txt
    pip install -r requirements.txt
  • 디렉토리 이동

    코드 블럭
    cd ~/kubespray
  • inventory

    코드 블럭
    cp -R /opt/kubespray-2.23-git~/kubespray/inventory/sample /opt/kubespray-2.23-git~/kubespray/inventory/k8s
    cd /opt~/kubespray-2.23-git/kubespray/inventory/k8s
    
    vi inventory.ini 
    코드 블럭
    [all]
    cp-k8s-master01 ansible_host=192.168.1102.2110
    w1-k8s-master02 ansible_host=192.168.1102.22101
    w2-k8s-master03 ansible_host=192.168.1102.23102
    k8s-worker01 ansible_host=192.168.110.24
    k8s-worker02w2-k8s ansible_host=192.168.1102.25103
    
    [kube_control_plane]
    k8scp-master01
    k8s-master02
    k8s-master03
    
    [etcd]
    k8s-master01
    k8s-master02
    k8s-master03cp-k8s
    
    [kube_node]
    w1-k8s
    w2-worker01k8s
    w3-k8s-worker02
    
    [calico_rr]
    
    [k8s_cluster:children]
    kube_control_plane
    kube_node
    calico_rr


2.3 Kuberntes 배포

  • ssh 접속 확인

    코드 블럭
    ansible -i /opt~/kubespray-2.23-git/kubespray/inventory/k8s/inventory.ini -m ping all
  • 클러스터 배포

    코드 블럭
    ansible-playbook -i /opt/kubespray-2.23-git~/kubespray/inventory/k8s/inventory.ini /opt/kubespary-2.23-git/~/kubespray/cluster.yml
  • node 상태 확인

    코드 블럭
    kubectl get nodes -o wide

...

참고) https://rancherdesktop.io/

첨부 파일