generated from infra/template
12 changed files with 140 additions and 61 deletions
-
5.drone.yml
-
9Makefile
-
7README.md
-
15inventory/hosts
-
31playbooks/k8s-dev/init.yml
-
6roles/common/tasks/main.yml
-
2roles/docker/tasks/main.yml
-
45roles/k8s-init-first-master/tasks/main.yml
-
5roles/k8s-init-machines/tasks/main.yml
-
55roles/k8s-init-machines/tasks/other.yml
-
14roles/k8s-init-workers/tasks/main.yml
-
7roles/k8s-join-workers-to-first-master/tasks/main.yml
@ -0,0 +1,31 @@ |
|||||
|
--- |
||||
|
- name: k8s-units playbook |
||||
|
hosts: k8s-dev |
||||
|
become: true |
||||
|
roles: |
||||
|
- common |
||||
|
- docker |
||||
|
- k8s-init-machines |
||||
|
|
||||
|
- name: k8s-units playbook 2 |
||||
|
hosts: k8s-dev-master-first |
||||
|
become: true |
||||
|
vars_prompt: |
||||
|
- name: "k8s_master_ip" |
||||
|
prompt: "Enter the Apiserver advertise address, example: 192.168.1.200" |
||||
|
private: no |
||||
|
roles: |
||||
|
- k8s-init-first-master |
||||
|
|
||||
|
- name: k8s-units playbook 3 |
||||
|
hosts: k8s-dev-worker |
||||
|
become: true |
||||
|
roles: |
||||
|
- k8s-init-workers |
||||
|
|
||||
|
- name: k8s-units playbook 4 |
||||
|
hosts: k8s-dev-master-first |
||||
|
become: true |
||||
|
roles: |
||||
|
- k8s-join-workers-to-first-master |
||||
|
... |
@ -0,0 +1,45 @@ |
|||||
|
--- |
||||
|
#- name: Intilizing Kubernetes Cluster |
||||
|
# command: kubeadm init --pod-network-cidr 192.168.0.0/16 --apiserver-advertise-address "{{ k8s_master_ip }}" |
||||
|
# run_once: true |
||||
|
# delegate_to: "{{ k8s_master_ip }}" |
||||
|
|
||||
|
- name: Create directory for kube config. |
||||
|
file: |
||||
|
path: /home/fedy95/.kube |
||||
|
state: directory |
||||
|
owner: "fedy95" |
||||
|
group: "fedy95" |
||||
|
mode: 0755 |
||||
|
|
||||
|
- name: Copy /etc/kubernetes/admin.conf to user home directory /home/fedy95/.kube/config. |
||||
|
copy: |
||||
|
src: /etc/kubernetes/admin.conf |
||||
|
dest: /home/fedy95/.kube/config |
||||
|
remote_src: yes |
||||
|
owner: "fedy95" |
||||
|
group: "fedy95" |
||||
|
mode: '0644' |
||||
|
|
||||
|
- name: Remove the cache directory. |
||||
|
file: |
||||
|
path: /home/fedy95/.kube/cache |
||||
|
state: absent |
||||
|
|
||||
|
- name: Create Pod Network & RBAC. |
||||
|
command: "{{ item }}" |
||||
|
with_items: |
||||
|
- kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml |
||||
|
- kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml |
||||
|
|
||||
|
- name: Get the token for joining the nodes with Kuberentes master. |
||||
|
shell: kubeadm token create --print-join-command |
||||
|
register: kubernetes_join_command |
||||
|
|
||||
|
- debug: |
||||
|
msg: "{{ kubernetes_join_command.stdout }}" |
||||
|
|
||||
|
- name: Copy join command to local file. |
||||
|
become: false |
||||
|
local_action: copy content="{{ kubernetes_join_command.stdout_lines[0] }}" dest="/tmp/kubernetes_join_command" mode=0777 |
||||
|
... |
@ -1,55 +0,0 @@ |
|||||
- hosts: k8s-master |
|
||||
become: yes |
|
||||
tasks: |
|
||||
- name: install kubectl |
|
||||
apt: |
|
||||
name: kubectl={{ kube_version }} |
|
||||
state: present |
|
||||
force: yes |
|
||||
|
|
||||
- name: initialize the cluster |
|
||||
shell: kubeadm init --pod-network-cidr=10.244.0.0/16 >> cluster_initialized.txt |
|
||||
args: |
|
||||
chdir: $HOME |
|
||||
creates: cluster_initialized.txt |
|
||||
|
|
||||
- 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: $HOME/.kube/config |
|
||||
remote_src: yes |
|
||||
owner: fedy95 |
|
||||
|
|
||||
- name: install Pod network |
|
||||
shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml >> pod_network_setup.txt |
|
||||
args: |
|
||||
chdir: $HOME |
|
||||
creates: pod_network_setup.txt |
|
||||
|
|
||||
- hosts: k8s-master |
|
||||
become: yes |
|
||||
gather_facts: false |
|
||||
tasks: |
|
||||
- name: get join command |
|
||||
shell: kubeadm token create --print-join-command |
|
||||
register: join_command_raw |
|
||||
|
|
||||
- name: set join command |
|
||||
set_fact: |
|
||||
join_command: "{{ join_command_raw.stdout_lines[0] }}" |
|
||||
|
|
||||
|
|
||||
- hosts: k8s-workers |
|
||||
become: yes |
|
||||
tasks: |
|
||||
- name: join cluster |
|
||||
shell: "{{ hostvars['master'].join_command }} >> node_joined.txt" |
|
||||
args: |
|
||||
chdir: $HOME |
|
||||
creates: node_joined.txt |
|
@ -0,0 +1,14 @@ |
|||||
|
--- |
||||
|
- name: Copy join command to worker nodes. |
||||
|
copy: |
||||
|
src: /tmp/kubernetes_join_command |
||||
|
dest: /tmp/kubernetes_join_command |
||||
|
mode: 0777 |
||||
|
|
||||
|
- name: Join the Worker nodes with master. |
||||
|
command: sh /tmp/kubernetes_join_command |
||||
|
register: joined_or_not |
||||
|
|
||||
|
- debug: |
||||
|
msg: "{{ joined_or_not.stdout }}" |
||||
|
... |
@ -0,0 +1,7 @@ |
|||||
|
--- |
||||
|
- name: Configure kubectl command auto completion. |
||||
|
lineinfile: |
||||
|
dest: /home/fedy95/.bashrc |
||||
|
line: 'source <(kubectl completion bash)' |
||||
|
insertafter: EOF |
||||
|
... |
Reference in new issue