Kubespray의 cluster.yml을 실행하면 여러 호스트에 많은 작업이 이어진다. 실패한 task 하나를 이해하려면 그 task가 어느 role에서 왔는지뿐 아니라 어떤 play가 어떤 호스트에, 어떤 조건으로 그 role을 호출했는지를 찾아야 한다.

Kubespray 2.30.0 작업 폴더와 공식 v2.30.0 파일을 대조하며 플레이북의 실행 구조를 분석했다. 아래 내용은 설치 결과가 아니라 진입점·호스트 선택·role 호출 관계를 따라가는 과정이다.

1. 명령이 선택하는 대상과 권한

원래 사용한 명령 형태는 다음과 같다.

bash
ansible-playbook -i inventory/mycluster/hosts.yaml \
  --become --become-user=root \
  cluster.yml

-i는 inventory를 고르고 cluster.yml은 저장소 루트의 진입점을 지정한다. --become은 권한 상승을 요청하며 --become-user=root는 상승 후의 사용자를 고른다. 이것이 SSH 접속 사용자까지 root로 지정하거나 인증·권한이 자동 확보된다는 뜻은 아니다.

이 예제의 inventory 경로는 hosts.yaml이다. INI 형식 inventory를 사용하는 구성에서는 해당 파일 경로를 입력한다. 실행 대상은 inventory·commit과 Ansible 환경의 조합으로 결정된다.

2. 88바이트 진입점 안에는 설치 본문이 없다

당시 ls와 cat 출력은 다음과 같다.

plain text
# ls -al | grep cluster.yml 
-rw-rw-r--  1 root root    88 Jan 29 18:15 cluster.yml

root@bastion:~/kube/kubespray-2.30.0# cat cluster.yml 
---
- name: Install Kubernetes
  ansible.builtin.import_playbook: playbooks/cluster.yml

최상위 파일은 playbooks/cluster.yml을 import한다. 따라서 설치 단계가 궁금하면 그 파일로 들어가야 한다. 파일이 짧다는 것은 설치가 단순하다는 의미가 아니라 실제 구성이 나뉘어 있다는 뜻이다. v2.30.0 최상위 진입점

ansible.builtin.import_playbook은 플레이북 수준에서 다른 플레이북을 정적으로 가져온다. task 수준의 copy·file·shell 모듈과는 사용하는 위치가 다르다. ansible.builtin은 컬렉션 이름이고 뒤의 이름은 기능 식별자다.

정적 import는 파싱 단계에 구성을 반영하지만, 실제 작업은 play의 대상·조건과 실행 전략에 따라 수행된다. 동적 include_tasks·include_role과 처리 시점·태그·목록 표시 동작이 다르다. Ansible의 import와 include

3. 파일을 읽을 때 구분할 네 가지

playbook에서 먼저 볼 것은 단계 이름, hosts, roles, when이다. 이름은 작성자의 의도를 설명하고 hosts는 inventory에서 대상을 고른다. roles는 작업 구현을 연결하며 조건은 그 호출이 적용될 상황을 제한한다.

예를 들어 설치 준비 play의 hosts: k8s_cluster:etcd는 두 그룹의 합집합이다. k8s_cluster 안의 etcd만 선택하는 경로 표기가 아니다. kube_control_plane[0]은 inventory 그룹에서 첫 호스트를 선택하는 패턴이며 그 호스트가 언제나 런타임의 leader라는 뜻은 아니다. Ansible 호스트 패턴

yaml
# 당시 prepare play의 일부
hosts: k8s_cluster:etcd
gather_facts: false
roles:
  - { role: kubespray_defaults }
  - { role: kubernetes/preinstall, tags: preinstall }
  - { role: container-engine, when: deploy_container_engine }
  - { role: download, when: "not skip_downloads" }

gather_facts: false는 이 play에서 자동 facts 수집을 하지 않는다는 뜻이다. 앞에서 internal_facts.yml을 가져오므로 “Kubespray 전체가 facts를 전혀 쓰지 않는다”고 해석할 수 없다. any_errors_fatal·환경 변수·태그도 실제 실행 범위와 실패 처리에 영향을 주므로 role 이름만 떼어 읽지 않는다.

4. 설치 파일의 큰 흐름

v2.30.0은 공통 준비·facts, 설치 준비, etcd, 노드·컨트롤 플레인, kubeadm·네트워크, 추가 구성·DNS 후처리로 이어진다. 각 단계의 role과 호출 조건은 다음 발췌에 나타난다. v2.30.0 playbooks/cluster.yml

각 play에서는 Ansible의 호스트별 실행 전략과 role 내부 조건·위임·handler가 적용된다. 따라서 파일에 나열된 전체 단계와 개별 호스트가 수행하는 작업은 다를 수 있다.

역할의 이름만으로 네트워크나 애플리케이션의 성공까지 결론내릴 수도 없다. 예를 들어 network_plugin 호출이 나타나는 것과 각 노드의 CNI가 준비되고 Pod 간 통신이 성공한 것은 다른 확인 단계다.

당시 2.30.0 내부 cluster.yml 전체 발췌
plain text
root@bastion:~/kube/kubespray-2.30.0/playbooks# cat cluster.yml 
---
- name: Common tasks for every playbooks
  import_playbook: boilerplate.yml

- name: Gather facts
  import_playbook: internal_facts.yml

- name: Prepare for etcd install
  hosts: k8s_cluster:etcd
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes/preinstall, tags: preinstall }
    - { role: "container-engine", tags: "container-engine", when: deploy_container_engine }
    - { role: download, tags: download, when: "not skip_downloads" }

- name: Install etcd
  vars:
    etcd_cluster_setup: true
    etcd_events_cluster_setup: "{{ etcd_events_cluster_enabled }}"
  import_playbook: install_etcd.yml

- name: Install Kubernetes nodes
  hosts: k8s_cluster
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes/node, tags: node }

- name: Install the control plane
  hosts: kube_control_plane
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes/control-plane, tags: control-plane }
    - { role: kubernetes/client, tags: client }
    - { role: kubernetes-apps/cluster_roles, tags: cluster-roles }

- name: Invoke kubeadm and install a CNI
  hosts: k8s_cluster
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes/kubeadm, tags: kubeadm}
    - { role: kubernetes/node-label, tags: node-label }
    - { role: kubernetes/node-taint, tags: node-taint }
    - { role: kubernetes-apps/common_crds }
    - { role: network_plugin, tags: network }

- name: Install Calico Route Reflector
  hosts: calico_rr
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: network_plugin/calico/rr, tags: ['network', 'calico_rr'] }

- name: Patch Kubernetes for Windows
  hosts: kube_control_plane[0]
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: win_nodes/kubernetes_patch, tags: ["control-plane", "win_nodes"] }

- name: Install Kubernetes apps
  hosts: kube_control_plane
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes-apps/external_cloud_controller, tags: external-cloud-controller }
    - { role: kubernetes-apps/policy_controller, tags: policy-controller }
    - { role: kubernetes-apps/ingress_controller, tags: ingress-controller }
    - { role: kubernetes-apps/external_provisioner, tags: external-provisioner }
    - { role: kubernetes-apps, tags: apps }

- name: Apply resolv.conf changes now that cluster DNS is up
  hosts: k8s_cluster
  gather_facts: false
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  environment: "{{ proxy_disable_env }}"
  roles:
    - { role: kubespray_defaults }
    - { role: kubernetes/preinstall, when: "dns_mode != 'none' and resolvconf_mode == 'host_resolvconf'", tags: resolvconf, dns_late: true }

발췌에는 Calico route reflector와 Windows 관련 role도 등장한다. 항목의 존재와 실제 적용 여부를 구분하려면 대상 그룹·해당 role의 조건을 함께 봐야 한다. 이 파일만으로 모든 설치에서 모든 플러그인·Windows 설정을 적용했다고 보고할 수 없다.

5. 실패한 작업에서 원인을 거슬러 찾기

실패 로그를 받았을 때는 실패 호스트·play·role/task 이름과 사용한 inventory·commit을 먼저 묶는다. 같은 task 이름이라도 다른 호출 문맥에서 실행될 수 있기 때문이다.

다음은 배포를 시작하기 전 구조를 조사하는 명령 예다.

bash
ansible-inventory -i inventory/mycluster/hosts.yaml --graph
ansible-playbook -i inventory/mycluster/hosts.yaml cluster.yml --syntax-check
ansible-playbook -i inventory/mycluster/hosts.yaml cluster.yml --list-hosts
ansible-playbook -i inventory/mycluster/hosts.yaml cluster.yml --list-tasks

# 오류에 나온 역할·조건·변수의 정의를 검색한다.
rg -n 'deploy_container_engine|skip_downloads|dns_late' playbooks roles inventory/mycluster

syntax-check는 구문 검사이고 list-hosts·list-tasks는 실행 대상·구조를 살피는 도구다. SSH 인증, 실제 노드 자원, API 가용성과 설치 성공을 검증하지 않는다. 동적 include 내부 작업은 목록에 드러나는 범위가 다를 수 있다.

변수 검색 결과에서는 선언과 사용을 구분한다. role defaults를 발견했다면 inventory와 추가 전달 값이 그것을 어떻게 바꾸는지 확인하고, task 파일에서 실제 조건과 생성 경로를 읽는다. 전체 변수 덤프에는 자격증명이 들어갈 수 있어 필요한 값만 확인한다.

6. 부분 재실행은 단계를 건너뛰는 결정이다

태그나 --limit를 쓰면 조사 범위를 줄일 수 있지만 필요한 선행 작업까지 빠질 수 있다. 다운로드·facts·인증서 생성·다른 호스트 위임·클러스터 전체 구성을 고려하지 않고 실패 role만 떼어 재실행하면 새 오류가 생길 수 있다.

--check도 완전한 클러스터 예행 실행은 아니다. module별 지원 범위와 task 설정에 따라 동작이 달라지며 실제 변경 후에만 알 수 있는 상태는 예측하지 못할 수 있다. diff에는 민감한 값이 드러날 수 있어 대상과 출력 보관 범위를 정한다. Ansible check·diff mode

재시도할 때는 어떤 상태까지 완료됐는지, 해당 작업이 반복 실행을 고려하는지, 서비스 재시작·업데이트에 어떤 영향이 있는지를 확인한다. playbook을 읽는 것과 운영 변경을 실행하는 일을 구분해야 한다.

7. 읽기 결과와 실제 설치 결과를 나누기

이 기록에서 확인한 것은 명령의 입력, 최상위 import와 내부 playbook의 구조다. SSH 접속, role별 성공 출력, Kubernetes 노드 Ready, CNI 통신과 애플리케이션 동작 결과는 포함되어 있지 않다.

실제 설치 기록을 남길 때는 commit·inventory·주요 변경 변수·실행 명령과 결과를 함께 저장하고, 해당 변경 범위의 클러스터 상태를 확인한다. 실패 task를 찾는 목적이라면 최상위 import → play의 대상·조건 → role의 task·template 순서로 읽으면 조사 경로가 분명해진다.

디렉터리별 역할은 다음 문서에서 참고할 수 있다. 그 문서는 2.28 계열의 별도 관측이므로 현재 2.30.0 실행 파일과 일치한다고 가정하지 않는다.

디렉터리 구조는 사용 중인 Kubespray release의 공식 저장소와 함께 확인한다.