add rancher local path for simple persistant volume claim
This commit is contained in:
@@ -6,15 +6,15 @@ all:
|
|||||||
control_plane:
|
control_plane:
|
||||||
hosts:
|
hosts:
|
||||||
controlplane:
|
controlplane:
|
||||||
ansible_host: 10.203.146.176
|
ansible_host: 10.203.146.7
|
||||||
workers:
|
workers:
|
||||||
hosts:
|
hosts:
|
||||||
node01:
|
node01:
|
||||||
ansible_host: 10.203.146.190
|
ansible_host: 10.203.146.55
|
||||||
node02:
|
node02:
|
||||||
ansible_host: 10.203.146.198
|
ansible_host: 10.203.146.254
|
||||||
node03:
|
node03:
|
||||||
ansible_host: 10.203.146.250
|
ansible_host: 10.203.146.131
|
||||||
vars:
|
vars:
|
||||||
ansible_user: ubuntu
|
ansible_user: ubuntu
|
||||||
ansible_become: yes
|
ansible_become: yes
|
||||||
|
|||||||
@@ -49,6 +49,17 @@
|
|||||||
tasks:
|
tasks:
|
||||||
- include_tasks: ../tasks/kubernetes/worker-join.yml
|
- include_tasks: ../tasks/kubernetes/worker-join.yml
|
||||||
|
|
||||||
|
- name: Deploy Rancher Local Path Provisioner
|
||||||
|
hosts: k8s_cluster
|
||||||
|
become: yes
|
||||||
|
vars_files:
|
||||||
|
- ../defaults/kubernetes.yml
|
||||||
|
tags:
|
||||||
|
- storage
|
||||||
|
- localpath
|
||||||
|
tasks:
|
||||||
|
- include_tasks: ../tasks/kubernetes/deploy-localpath.yml
|
||||||
|
|
||||||
- name: Validate Kubernetes cluster
|
- name: Validate Kubernetes cluster
|
||||||
hosts: k8s_cluster
|
hosts: k8s_cluster
|
||||||
become: yes
|
become: yes
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
# ansible/tasks/kubernetes/deploy-localpath.yml
|
||||||
|
# Deploy Rancher Local Path Provisioner to worker nodes
|
||||||
|
|
||||||
|
- name: Create local-path directory on worker nodes
|
||||||
|
file:
|
||||||
|
path: /opt/local-path-provisioner
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
delegate_to: "{{ item }}"
|
||||||
|
with_items: "{{ groups['workers'] }}"
|
||||||
|
|
||||||
|
- name: Download Local Path Provisioner YAML
|
||||||
|
get_url:
|
||||||
|
url: https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
|
||||||
|
dest: /tmp/local-path-storage.yaml
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: download_result
|
||||||
|
|
||||||
|
- name: Apply Local Path Provisioner YAML
|
||||||
|
shell: kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f /tmp/local-path-storage.yaml
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: apply_result
|
||||||
|
changed_when: apply_result.rc == 0
|
||||||
|
failed_when: apply_result.rc != 0 and "already exists" not in apply_result.stderr
|
||||||
|
|
||||||
|
- name: Wait for Local Path Provisioner to be ready
|
||||||
|
shell: >
|
||||||
|
kubectl --kubeconfig=/etc/kubernetes/admin.conf -n local-path-storage wait
|
||||||
|
--for=condition=ready pod
|
||||||
|
--selector=app=local-path-provisioner
|
||||||
|
--timeout=60s
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: wait_result
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Get Local Path Provisioner status
|
||||||
|
shell: >
|
||||||
|
kubectl --kubeconfig=/etc/kubernetes/admin.conf -n local-path-storage get pod
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: status_result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Display Local Path Provisioner status
|
||||||
|
debug:
|
||||||
|
msg: "{{ status_result.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: Verify StorageClass was created
|
||||||
|
shell: >
|
||||||
|
kubectl --kubeconfig=/etc/kubernetes/admin.conf get storageclass | grep local-path
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: sc_result
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Set Local Path Provisioner as default StorageClass
|
||||||
|
shell: >
|
||||||
|
kubectl --kubeconfig=/etc/kubernetes/admin.conf patch storageclass local-path
|
||||||
|
-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
|
||||||
|
delegate_to: "{{ groups['control_plane'][0] }}"
|
||||||
|
register: default_sc_result
|
||||||
|
changed_when: default_sc_result.rc == 0
|
||||||
|
failed_when: false
|
||||||
|
when: sc_result.rc == 0
|
||||||
Reference in New Issue
Block a user