blob: 3c2ff77f48080c9aabd368d304d905a3dfed12ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# Stunnel and NFS Configuration for r1 and r2
This document provides step-by-step instructions for configuring stunnel and NFS mounts on r1 and r2 Rocky Linux systems to connect to the f3s storage cluster.
## Prerequisites
- Root access on r1 and r2
- Network connectivity to f0 (for copying the certificate)
- Network connectivity to the CARP VIP (192.168.1.138)
## Overview
The configuration provides:
- Encrypted NFS traffic using stunnel
- Automatic failover via CARP VIP (192.168.1.138)
- Persistent mounts across reboots
- Access to /data/nfs/k3svolumes for Kubernetes storage
## Configuration Steps
### Step 1: Install stunnel
```bash
dnf install -y stunnel
```
### Step 2: Copy the stunnel certificate from f0
First, create the directory:
```bash
mkdir -p /etc/stunnel
```
Then copy the certificate from f0. On f0, run:
```bash
scp /usr/local/etc/stunnel/stunnel.pem root@r1:/etc/stunnel/
scp /usr/local/etc/stunnel/stunnel.pem root@r2:/etc/stunnel/
```
### Step 3: Create stunnel client configuration
Create `/etc/stunnel/stunnel.conf`:
```bash
cat > /etc/stunnel/stunnel.conf <<'EOF'
cert = /etc/stunnel/stunnel.pem
client = yes
[nfs-ha]
accept = 127.0.0.1:2323
connect = 192.168.1.138:2323
EOF
```
### Step 4: Create systemd service for stunnel
Create `/etc/systemd/system/stunnel.service`:
```bash
cat > /etc/systemd/system/stunnel.service <<'EOF'
[Unit]
Description=SSL tunnel for network daemons
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/stunnel /etc/stunnel/stunnel.conf
ExecStop=/usr/bin/killall stunnel
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
```
### Step 5: Enable and start stunnel
```bash
systemctl daemon-reload
systemctl enable stunnel
systemctl start stunnel
systemctl status stunnel
```
### Step 6: Create NFS mount point
```bash
mkdir -p /data/nfs/k3svolumes
```
### Step 7: Test mount NFS through stunnel
```bash
mount -t nfs4 -o port=2323 127.0.0.1:/data/nfs/k3svolumes /data/nfs/k3svolumes
```
### Step 8: Verify the mount
```bash
mount | grep k3svolumes
df -h /data/nfs/k3svolumes
ls -la /data/nfs/k3svolumes/
```
### Step 9: Configure persistent mount
First unmount the test mount:
```bash
umount /data/nfs/k3svolumes
```
Add to `/etc/fstab`:
```bash
echo "127.0.0.1:/data/nfs/k3svolumes /data/nfs/k3svolumes nfs4 port=2323,_netdev 0 0" >> /etc/fstab
```
Mount using fstab:
```bash
mount /data/nfs/k3svolumes
```
## Automated Installation
A script is available to automate all these steps:
```bash
# Download and run the configuration script
curl -O https://raw.githubusercontent.com/.../configure-stunnel-nfs-r1-r2.sh
chmod +x configure-stunnel-nfs-r1-r2.sh
./configure-stunnel-nfs-r1-r2.sh
```
## Verification Commands
After configuration, verify everything is working:
```bash
# Check stunnel service
systemctl status stunnel
# Check NFS mount
mount | grep k3svolumes
df -h /data/nfs/k3svolumes
# Test write access
echo "Test from $(hostname) at $(date)" > /data/nfs/k3svolumes/test-$(hostname).txt
cat /data/nfs/k3svolumes/test-$(hostname).txt
# Check stunnel connection
ss -tlnp | grep 2323
```
## Troubleshooting
### Stunnel won't start
Check the logs:
```bash
journalctl -u stunnel -n 50
```
Common issues:
- Certificate file missing or wrong permissions
- Port 2323 already in use
- Configuration syntax error
### NFS mount fails
Check connectivity:
```bash
# Test if stunnel is listening
telnet 127.0.0.1 2323
# Check if CARP VIP is reachable
ping -c 3 192.168.1.138
# Try mounting with verbose output
mount -v -t nfs4 -o port=2323 127.0.0.1:/data/nfs/k3svolumes /data/nfs/k3svolumes
```
### Mount not persistent after reboot
Verify fstab entry:
```bash
grep k3svolumes /etc/fstab
```
Test fstab mount:
```bash
mount -a
```
Check for systemd mount errors:
```bash
systemctl --failed
journalctl -b | grep mount
```
### Permission denied errors
The NFS export on f0/f1 maps root, so permission issues are rare. If they occur:
```bash
# Check export configuration on NFS server
showmount -e 192.168.1.138
# Verify your IP is allowed in the exports
# r0: 192.168.1.120
# r1: 192.168.1.121
# r2: 192.168.1.122
```
## Security Considerations
- All NFS traffic is encrypted through stunnel
- The certificate provides both authentication and encryption
- Access is restricted by IP address on the NFS server
- Root access is mapped (maproot=root) for Kubernetes operations
## Integration with Kubernetes
Once configured, Kubernetes can use this mount for persistent storage:
```yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: 127.0.0.1 # Local stunnel
path: /data/nfs/k3svolumes
mountOptions:
- port=2323
- nfsvers=4
```
## Maintenance
### Restarting services
```bash
# Restart stunnel
systemctl restart stunnel
# Remount NFS
umount /data/nfs/k3svolumes
mount /data/nfs/k3svolumes
```
### Updating certificates
When certificates expire (after 10 years):
1. Generate new certificate on f0
2. Copy to all clients (r0, r1, r2)
3. Restart stunnel on all hosts
### Monitoring
Add to your monitoring system:
- stunnel service status
- NFS mount presence
- Disk space on /data/nfs/k3svolumes
- Network connectivity to 192.168.1.138:2323
## Summary
After completing these steps on both r1 and r2:
1. **Stunnel** provides encrypted tunnel to NFS server
2. **NFS** mounts through stunnel on port 2323
3. **CARP VIP** (192.168.1.138) ensures automatic failover
4. **Persistent mount** via /etc/fstab survives reboots
5. **Kubernetes** can use /data/nfs/k3svolumes for persistent volumes
The same configuration works on r0, r1, and r2 with no modifications needed.
|