Skip to content

Commit 0080bfd

Browse files
committed
add scripts for nfs-server on IBMCloud VSI
Signed-off-by: anandrkskd <[email protected]>
1 parent 47dfe74 commit 0080bfd

File tree

6 files changed

+229
-0
lines changed

6 files changed

+229
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ReadMe
2+
This directory contains yaml files to create NFS server with
3+
4+
### NFS provisioner (how to configure nfs for cluster)
5+
6+
You can run the following commands upon a cluster to deploy the NFS provisioner to this cluster (either Kubernetes or OpenShift). You will need to uninstall the "Block Storage for VPC" add-on installed by default, to make the NFS provisioner work correctly.
7+
8+
```
9+
$ helm repo add nfs-subdir-external-provisioner \
10+
https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
11+
12+
$ helm install nfs-subdir-external-provisioner \
13+
nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
14+
--set nfs.server=<IP_FOR_NFS> \
15+
--set nfs.path=/mnt/nfs \
16+
--set storageClass.defaultClass=true \
17+
--set storageClass.onDelete=delete
18+
--version=4.0.15
19+
```
20+
21+
> learn more about nfs-subdir-external-provisioner from https://artifacthub.io/packages/helm/nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
22+
23+
### check if nfs is working or not
24+
25+
login using the floating IP
26+
27+
### **NOTE**
28+
29+
ibmcoud storage provided with cluster doesnt works with nfs storge(if nfs storage is set as default). So make sure to diable addon `vpc-block-csi-driver` from cluster for which you want to use **nfs-storage**
30+
31+
#### *command to delete/remove storage addons from cluster*
32+
33+
```shell
34+
ibmcloud ks cluster addon disable vpc-block-csi-driver
35+
```
36+
37+
### helpful commands
38+
39+
1. Fetch IP for nfs configuration
40+
```shell
41+
IP_FOR_NFS=$(ibmcloud is instance <nfs-instance-name> --output json | jq -r ".primary_network_interface.primary_ip.address")
42+
```
43+
44+
2. Fetch Floating IP of NFS-Server
45+
```shell
46+
NFS_IP=$(ibmcloud is instance k8s-nfs-server --output json | jq -r ".primary_network_interface.floating_ips[0].address" )
47+
```
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
- name: Create NFS vsi for Clusters on IBM Cloud
3+
hosts: localhost
4+
collections:
5+
- ibm.cloudcollection
6+
tasks:
7+
- name: Fetch the variables from var file
8+
include_vars:
9+
file: vars.yml
10+
11+
- name: Configure Resource Group
12+
ibm_resource_group:
13+
name: "{{ name_prefix }}-group"
14+
state: available
15+
register: rg_create_output
16+
17+
- name: Save Resource Group as fact
18+
set_fact:
19+
cacheable: True
20+
rg: "{{ rg_create_output.resource }}"
21+
when: rg_create_output.rc==0
22+
23+
- name: Configure VPC
24+
ibm_is_vpc:
25+
name: "{{ name_prefix }}-vpc"
26+
resource_group: "{{ rg.id }}"
27+
state: available
28+
register: vpc_create_output
29+
30+
- name: Save VPC as fact
31+
set_fact:
32+
cacheable: True
33+
vpc: "{{ vpc_create_output.resource }}"
34+
when: vpc_create_output.rc==0
35+
36+
# ibm_is_security_group_rule is not idempotent - comment this block if you want to run several times
37+
- name: Configure Security Group Rule to open SSH on the NFS server
38+
ibm_is_security_group_rule:
39+
group: "{{ vpc.default_security_group }}"
40+
direction: inbound
41+
remote: 0.0.0.0/0
42+
tcp:
43+
- port_max: 22
44+
port_min: 22
45+
state: available
46+
47+
- name: Configure Public Gateway
48+
ibm_is_public_gateway:
49+
name: "{{ name_prefix }}-gw"
50+
resource_group: "{{ rg.id }}"
51+
zone: "{{ cluster_zone }}"
52+
vpc: "{{ vpc.id }}"
53+
state: available
54+
register: gw_create_output
55+
56+
- name: Save Public Gateway as fact
57+
set_fact:
58+
cacheable: True
59+
gw: "{{ gw_create_output.resource }}"
60+
when: gw_create_output.rc==0
61+
62+
- name: Configure VPC Subnet
63+
ibm_is_subnet:
64+
name: "{{ name_prefix }}-subnet"
65+
resource_group: "{{ rg.id }}"
66+
vpc: "{{ vpc.id }}"
67+
zone: "{{ cluster_zone }}"
68+
total_ipv4_address_count: "{{ total_ipv4_address_count }}"
69+
public_gateway: "{{ gw.id }}"
70+
state: available
71+
register: subnet_create_output
72+
73+
- name: Save VPC Subnet as fact
74+
set_fact:
75+
cacheable: True
76+
subnet: "{{ subnet_create_output.resource }}"
77+
when: subnet_create_output.rc==0
78+
79+
- name: Retrieve image list
80+
ibm_is_images_info:
81+
register: images_list
82+
83+
- name: Set VM image name/id dictionary fact
84+
set_fact:
85+
cacheable: True
86+
image_dict: "{{ images_list.resource.images |
87+
items2dict(key_name='name', value_name='id') }}"
88+
89+
- name: Configure SSH Key
90+
ibm_is_ssh_key:
91+
name: "ansible-ssh-key"
92+
public_key: "{{ ssh_public_key }}"
93+
register: ssh_key_create_output
94+
95+
- name: Save SSH Key as fact
96+
set_fact:
97+
cacheable: True
98+
ssh_key: "{{ ssh_key_create_output.resource }}"
99+
100+
- name: Configure VSI for NFS server
101+
ibm_is_instance:
102+
name: "{{ name_prefix }}-nfs"
103+
resource_group: "{{ rg.id }}"
104+
vpc: "{{ vpc.id }}"
105+
profile: "bx2-2x8"
106+
image: "{{ image_dict[nfs_image] }}"
107+
keys:
108+
- "{{ ssh_key.id }}"
109+
primary_network_interface:
110+
- subnet: "{{ subnet.id }}"
111+
zone: "{{ cluster_zone }}"
112+
state: available
113+
register: nfs_create_output
114+
115+
- name: Save VSI as fact
116+
set_fact:
117+
cacheable: True
118+
nfs: "{{ nfs_create_output.resource }}"
119+
120+
- name: Configure Floating IP Address
121+
ibm_is_floating_ip:
122+
name: "{{ name_prefix }}-nfs-ip"
123+
target: "{{ nfs.primary_network_interface[0]['id'] }}"
124+
state: available
125+
register: nfsip_create_output
126+
127+
- name: Save Floating IP as fact
128+
set_fact:
129+
cacheable: True
130+
nfsip: "{{ nfsip_create_output.resource }}"
131+
132+
- name: Add NFS to Ansible inventory
133+
add_host:
134+
name: "{{ nfsip.address }}"
135+
ansible_user: root
136+
groups: new_vsi
137+
ansible_ssh_extra_args: -o StrictHostKeyChecking=no
138+
139+
- local_action:
140+
module: copy
141+
content: "{{ nfs.primary_network_interface.primary_ip.address }}"
142+
dest: "{{ nfs_ip_file }}"
143+
144+
- name: Check Ansible connection to new NFS server
145+
hosts: new_vsi
146+
gather_facts: False
147+
tasks:
148+
- name: Wait for VSI to become reachable over SSH
149+
wait_for_connection:
150+
151+
- name: Configure VSI as NFS server
152+
hosts: new_vsi
153+
tasks:
154+
- name: Install required packages
155+
ansible.builtin.package:
156+
name: nfs-kernel-server
157+
state: present
158+
159+
- name: Create shared directory
160+
ansible.builtin.file:
161+
path: /mnt/nfs
162+
state: directory
163+
mode: '0777'
164+
165+
- name: Create NFS configuration
166+
copy:
167+
content: "/mnt/nfs *(rw,no_root_squash)"
168+
dest: "/etc/exports"
169+
170+
- name: Restart service nfs-kernel-server
171+
ansible.builtin.service:
172+
name: nfs-kernel-server
173+
state: restarted

scripts/ansible/Cluster/NFS-vm/manual-changes/Readme.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
collections:
3+
- ibm.cloudcollection
4+
- name: kubernetes.core
5+
version: 2.0.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
total_ipv4_address_count: 256
3+
nfs_ip_file: /tmp/nfs_ip_ibmcloud
4+
nfs_image: ibm-ubuntu-20-04-2-minimal-amd64-1

scripts/ansible/README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)