Ubuntu-18.04
我正在嘗試使用 ansible 和以下劇本在系統上設定 Kubernetes 叢集。
kube-dependency.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