Skip to content

Commit 0ff1af1

Browse files
authored
cleanup docs (#1240)
Signed-off-by: makhov <[email protected]>
1 parent f95d43a commit 0ff1af1

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/capi-remote.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,78 @@ spec:
207207
```
208208

209209
When CAPI controller creates a `RemoteMachine` from template object for the `K0sControlPlane`, k0smotron will pick one of the `PooledRemoteMachine` objects and use it's values for the `RemoteMachine` object.
210+
211+
### Using Sudo for Commands
212+
213+
When connecting to remote machines, you may need to execute commands with elevated privileges.
214+
The `useSudo` field allows k0smotron to wrap all executed commands with `sudo`. This is particularly useful when the SSH user doesn't have root privileges but has sudo access:
215+
216+
```yaml
217+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
218+
kind: RemoteMachine
219+
metadata:
220+
name: remote-test-0
221+
namespace: default
222+
spec:
223+
address: 1.2.3.4
224+
port: 22
225+
user: my-user
226+
useSudo: true
227+
sshKeyRef:
228+
name: my-user-key
229+
```
230+
231+
All commands executed on this machine will be prefixed with `sudo`, allowing operations that require elevated privileges.
232+
233+
## Cleanup
234+
235+
If you delete a `RemoteMachine`, k0smotron will perform cleanup of the k0s installation on the machine before deleting the object.
236+
237+
!!! note
238+
239+
Cleanup is only performed if the `RemoteMachine` has been successfully provisioned using `K0sWorkerConfig` or `K0sControlPlane` objects.
240+
If the `RemoteMachine` was provisioned using some other bootstrap provider, cleanup can be performed using `customCleanUpCommands` (see below).
241+
242+
The cleanup process for a k0s installation includes:
243+
244+
- Leaving the etcd cluster (if the node is a controller)
245+
- Stopping the k0s service
246+
- Running `k0s reset` to clean up k0s data ([read more](https://docs.k0sproject.io/stable/reset/)).
247+
248+
## Custom Cleanup Commands
249+
250+
k0smotron supports executing custom commands during the machine cleanup process when a `RemoteMachine` is deleted. This feature is particularly useful for:
251+
252+
- Cleaning up custom installations or configurations
253+
- Removing additional services or agents
254+
- Performing custom data cleanup
255+
- Handling special cleanup requirements
256+
257+
!!! warning
258+
When using `customCleanUpCommands`, you are responsible for the complete cleanup of the k0s installation. The default k0s cleanup will not be performed.
259+
260+
You can specify custom cleanup commands in the `customCleanUpCommands` field of a `RemoteMachine` or `PooledRemoteMachine`. For example:
261+
262+
```yaml
263+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
264+
kind: RemoteMachine
265+
metadata:
266+
name: remote-test-0
267+
namespace: default
268+
spec:
269+
address: 1.2.3.4
270+
port: 22
271+
user: root
272+
sshKeyRef:
273+
name: footloose-key
274+
customCleanUpCommands:
275+
- "systemctl stop custom-service"
276+
- "/custom-cleanup-script.sh"
277+
- "/usr/local/bin/k0s etcd leave"
278+
- "/usr/local/bin/k0s stop"
279+
- "/usr/local/bin/k0s reset"
280+
- "rm -rf /opt/custom-data"
281+
- "echo 'Custom cleanup completed'"
282+
```
283+
284+
`useSudo` field will be respected for `customCleanUpCommands` to execute the commands with elevated privileges if needed.

0 commit comments

Comments
 (0)