62 lines
1.9 KiB
YAML
62 lines
1.9 KiB
YAML
---
|
|
- import_playbook: task-number-playbook.yaml
|
|
|
|
- name: Install k8s
|
|
hosts: all_vms
|
|
remote_user: root
|
|
tasks:
|
|
- name: Install k8s packages
|
|
apt_rpm:
|
|
name:
|
|
- kubernetes-kubeadm
|
|
- kubernetes-kubelet
|
|
- kubernetes-crio
|
|
- cri-tools
|
|
update_cache: true
|
|
- name: start and enable k8s services
|
|
service:
|
|
name: "{{ item }}"
|
|
enabled: yes
|
|
state: started
|
|
loop:
|
|
- crio
|
|
- kubelet
|
|
|
|
- name: Init k8s master
|
|
hosts: master
|
|
tasks:
|
|
- name: run kubeadm init
|
|
#shell: "kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml | grep 'kubeadm join' -A 1 | sed 's|\\\\||' | xargs"
|
|
shell: "kubeadm init --pod-network-cidr=10.244.0.0/16 | grep 'kubeadm join' -A 1 | sed 's|\\\\||' | xargs"
|
|
register: kubeadm_init
|
|
changed_when: kubeadm_init.rc == 0
|
|
failed_when: kubeadm_init.rc not in [0, 2]
|
|
- name: save join command
|
|
copy:
|
|
content: "{{ kubeadm_init.stdout }}"
|
|
dest: kubeadm-join-command
|
|
when: kubeadm_init.rc == 0
|
|
- name: fetch join command
|
|
fetch:
|
|
src: kubeadm-join-command
|
|
dest: kubeadm-join-command
|
|
flat: yes
|
|
when: kubeadm_init.rc == 0
|
|
|
|
- name: Join k8s nodes
|
|
hosts: workers
|
|
tasks:
|
|
- name: run kubeadm join
|
|
command: "{{ lookup('file', 'kubeadm-join-command') }}"
|
|
register: kubeadm_join
|
|
changed_when: kubeadm_join.rc == 0
|
|
failed_when: kubeadm_join.rc not in [0, 2]
|
|
|
|
- name: Create network
|
|
hosts: master
|
|
tasks:
|
|
- name: create flannel network
|
|
command: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
|
environment:
|
|
KUBECONFIG: /etc/kubernetes/admin.conf
|