아래 플레이북과 함께 Ansible을 사용하여 시스템 에 Kubernetes 클러스터를 설정하려고 합니다 Ubuntu-18.04
.
kube-종속성.yml
- hosts: all
become: yes
remote_user: root
gather_facts: yes
connection: ssh
tasks:
- name: Make the Swap inactive
command: swapoff -a
- name: Ensure net.bridge.bridge-nf-call-ip6tables is set to 1
sysctl:
name: net.bridge.bridge-nf-call-ip6tables
value: 1
state: present
- name: Ensure net.bridge.bridge-nf-call-iptables is set to 1
sysctl:
name: net.bridge.bridge-nf-call-iptables
value: 1
state: present
- name: Install Docker
apt:
name: docker.io
state: present
update_cache: true
- name: Installing Prerequisites for Kubernetes
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- vim
- build-essential
- software-properties-common
state: present
- name: Enable service docker, and enable persistently
service:
name: docker
enabled: yes
- name: Add Kubernetes apt-key
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
- name: Add Kubernetes' APT repository
apt_repository:
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main
state: present
filename: 'kubernetes'
- name: Install kubelet
apt:
name: kubelet=1.19.4-00
state: present
update_cache: true
- name: Install kubeadm
apt:
name: kubeadm=1.19.4-00
state: present
- name: Enable service kubelet, and enable persistently
service:
name: kubelet
enabled: yes
- hosts: master
become: yes
tasks:
- name: Install kubectl
apt:
name: kubectl=1.19.4-00
state: present
force: yes
master.yml
- hosts: master
become: yes
remote_user: root
gather_facts: yes
connection: ssh
tasks:
- name: Intilizing Kubernetes Cluster
shell: kubeadm init --pod-network-cidr=10.244.0.0/16 >> cluster_initialized.txt
args:
chdir: $HOME
creates: cluster_initialized.txt
- pause: seconds=180
- name: create .kube directory
file:
path: $HOME/.kube
state: directory
mode: 0755
- name: Copy admin.conf to user's kube config
copy:
src: /etc/kubernetes/admin.conf
dest: /root/.kube/config
remote_src: yes
owner: root
mode: 0644
- name: Install Pod network Flannel
shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml >> pod_network_setup.txt
args:
chdir: $HOME
creates: pod_network_setup.txt
master.yml
아래 오류로 인해 항상 실패합니다.
TASK [Copy admin.conf to user's kube config] *************************************************************************************************************
fatal: [master]: FAILED! => {"changed": false, "msg": "Source /etc/kubernetes/admin.conf not found"}
PLAY RECAP ***********************************************************************************************************************************************
master : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
파일이 생성되지 않은 이유를 잘 모르겠습니다 admin.conf
. manifests
파일만 가지고 있습니다 .
~# ls /etc/kubernetes/
manifests
마스터 서버에서 주어진 콘텐츠가 포함된 아래 파일을 볼 수 있습니다.
# cat ~/cluster_initialized.txt
[init] Using Kubernetes version: v1.19.13
[preflight] Running pre-flight checks
에 문제가 있는 것 같습니다 kubeadm init
. 실제로 특별히 설치하고 싶습니다 Kubernetes - v1.19.4.
. 그러면 플레이북에 추가 구성이 누락되어 있습니까? 이 문제를 해결하는 방법을 제안해주세요. 감사해요.
답변1
버전을 지정하려면 플레이북에서 다음을 시도해 보세요.
kubeadm init --kubernetes-version stable-1.19.4 --pod-network-cidr=10.244.0.0/16 >> cluster_initialized.txt