You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Commands specified in `postStartCommands` are executed after k0s has started successfully. These commands run after the k0s service is running and the node is ready.
73
+
74
+
```yaml
75
+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
76
+
kind: K0sWorkerConfig
77
+
metadata:
78
+
name: worker-config
79
+
spec:
80
+
version: v1.27.2+k0s.0
81
+
postStartCommands:
82
+
- "systemctl enable monitoring-agent"
83
+
- "systemctl start monitoring-agent"
84
+
- "kubectl get nodes --kubeconfig=/var/lib/k0s/pki/admin.conf"
85
+
```
86
+
87
+
### Command Execution Order
88
+
89
+
The commands are executed in the following order:
90
+
91
+
1. **PreStartCommands** - Custom commands before k0s starts
92
+
2. **Download and Install** - k0s binary download and installation
93
+
3. **k0s start** - k0s service startup
94
+
4. **PostStartCommands** - Custom commands after k0s starts
95
+
96
+
### Use Cases
97
+
98
+
#### Installing Monitoring Agents
99
+
100
+
```yaml
101
+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
102
+
kind: K0sWorkerConfig
103
+
metadata:
104
+
name: worker-with-monitoring
105
+
spec:
106
+
version: v1.27.2+k0s.0
107
+
preStartCommands:
108
+
- "curl -fsSL https://get.docker.com | sh"
109
+
- "systemctl enable docker"
110
+
- "systemctl start docker"
111
+
postStartCommands:
112
+
- "docker run -d --name node-exporter -p 9100:9100 prom/node-exporter"
- Each command is executed in a separate shell session
154
+
- If any command fails, the bootstrap process will fail
155
+
- Commands are executed in the order they appear in the array
156
+
- Environment variables from the system are available to the commands
157
+
- The k0s kubeconfig is available at `/var/lib/k0s/pki/admin.conf` for PostStartCommands
158
+
43
159
The `infrastructureRef` in the `Machine` object specifies a reference to the provider-specific infrastructure required for the operation of the machine. In the above example, the kind `AWSMachine` indicates that the machine will be run on AWS. The parameters within `infrastructureRef` will be provider-specific and vary based on your chosen infrastructure.
Commands specified in `postStartCommands` are executed after k0s has started successfully. These commands run after the k0s service is running and the control plane is ready.
98
+
99
+
```yaml
100
+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
101
+
kind: K0sControlPlane
102
+
metadata:
103
+
name: cp-test
104
+
spec:
105
+
replicas: 3
106
+
k0sConfigSpec:
107
+
postStartCommands:
108
+
- "systemctl enable monitoring-agent"
109
+
- "systemctl start monitoring-agent"
110
+
- "kubectl get nodes --kubeconfig=/var/lib/k0s/pki/admin.conf"
111
+
```
112
+
113
+
### Command Execution Order
114
+
115
+
The commands are executed in the following order:
116
+
117
+
1. **PreStartCommands** - Custom commands before k0s starts
118
+
2. **Download and Install** - k0s binary download and installation
119
+
3. **k0s start** - k0s service startup
120
+
4. **PostStartCommands** - Custom commands after k0s starts
121
+
122
+
### Use Cases
123
+
124
+
#### Installing Monitoring Agents on Control Plane
125
+
126
+
```yaml
127
+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
128
+
kind: K0sControlPlane
129
+
metadata:
130
+
name: cp-with-monitoring
131
+
spec:
132
+
replicas: 3
133
+
k0sConfigSpec:
134
+
preStartCommands:
135
+
- "curl -fsSL https://get.docker.com | sh"
136
+
- "systemctl enable docker"
137
+
- "systemctl start docker"
138
+
postStartCommands:
139
+
- "docker run -d --name node-exporter -p 9100:9100 prom/node-exporter"
140
+
- "echo 'Node exporter started on port 9100'"
141
+
```
142
+
143
+
#### Configuring System Settings for Control Plane
0 commit comments