Skip to content

Commit 0db00bc

Browse files
authored
Merge pull request #4027 from replicatedhq/update-preflight-sb-spec-guidance
Update preflight and sb spec guidance
2 parents cae3448 + 05ca731 commit 0db00bc

5 files changed

Lines changed: 236 additions & 406 deletions

File tree

docs/vendor/preflight-defining.mdx

Lines changed: 68 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,91 @@
11
# Define preflight checks
22

3-
This topic describes how to define preflight checks in Helm and Kubernetes manifest-based applications. For more information about preflight checks, see [About Preflight Checks and Support Bundles](/vendor/preflight-support-bundle-about).
3+
This topic describes how to define custom preflight checks for your application. For more information about preflight checks, see [About Preflight Checks and Support Bundles](/vendor/preflight-support-bundle-about).
44

5-
The information in this topic applies to applications that are installed with Helm or with Replicated KOTS.
5+
## Add a preflight spec to a release
66

7-
## Step 1: Create the manifest file
7+
You can define custom preflight checks for your application by adding a preflight spec to your Helm chart templates.
88

9-
You can define preflight checks in a Kubernetes Secret or in a Preflight custom resource. The type of manifest file that you use depends on your application type (Helm or Kubernetes manifest-based) and the installation methods that your application supports (Helm, KOTS v1.101.0 or later, or KOTS v1.100.3 or earlier).
9+
To add a preflight spec to a release for your application:
1010

11-
* **Helm Applications**: For Helm applications, see the following guidance:
11+
1. In your Helm chart `templates` directory, create a YAML file. Name the file `preflights.yaml` or similar.
1212

13-
* **(Recommended) Helm or KOTS v1.101.0 or Later**: For Helm applications installed with Helm or KOTS v1.101.0 or later, define the preflight checks in a Kubernetes Secret in your Helm chart `templates`. See [Kubernetes Secret](#secret).
13+
1. In the YAML file, add the following to create a Kubernetes Secret with the label `troubleshoot.sh/kind: preflight`:
1414

15-
* **KOTS v1.100.3 or Earlier**: For Helm applications installed with KOTS v1.100.3 or earlier, define the preflight checks in a Preflight custom resource. See [Preflight Custom Resource](#preflight-cr).
15+
```yaml
16+
# templates/preflight.yaml
17+
apiVersion: v1
18+
kind: Secret
19+
metadata:
20+
# the troubleshoot.sh/kind: preflight label is required
21+
labels:
22+
troubleshoot.sh/kind: preflight
23+
name: "{{ .Release.Name }}-preflight-config"
24+
```
25+
26+
1. In the Secret, add a `stringData` field with a key named `preflight.yaml`. This ensures the `preflight` binary can use this Secret when it runs from the CLI.
27+
28+
```yaml
29+
# templates/preflight.yaml
30+
apiVersion: v1
31+
kind: Secret
32+
metadata:
33+
labels:
34+
troubleshoot.sh/kind: preflight
35+
name: "{{ .Release.Name }}-preflight-config"
36+
stringData:
37+
# add a preflight.yaml key under stringData
38+
preflight.yaml: |
39+
apiVersion: troubleshoot.sh/v1beta2
40+
kind: Preflight
41+
metadata:
42+
name: preflights
43+
spec:
44+
collectors: []
45+
analyzers: []
46+
```
47+
48+
1. Update `spec.collectors` and `spec.analyzers` with any collectors and analyzers that you want to use in the preflight checks for your application. For common examples, see [Examples of preflight specs](/vendor/preflight-examples).
49+
50+
For the complete list of available collectors and analyzers, see the [Collect](https://troubleshoot.sh/docs/collect/all/) and [Analyze](https://troubleshoot.sh/docs/analyze/) sections in the Troubleshoot documentation.
1651

17-
* **Kubernetes Manifest-Based Applications**: For Kubernetes manifest-based applications, define the preflight checks in a Preflight custom resource. See [Preflight Custom Resource](#preflight-cr).
52+
:::note
53+
Troubleshoot automatically includes the [clusterInfo](https://troubleshoot.sh/docs/collect/cluster-info/) and [clusterResources](https://troubleshoot.sh/docs/collect/cluster-resources/) collectors to gather information about the cluster and cluster resources. You do not need to manually include the `clusterInfo` or `clusterResources` collectors in the specification.
54+
55+
To use only the `clusterInfo` and `clusterResources` collectors, delete the `spec.collectors` key from the preflight spec.
56+
:::
1857

19-
### Kubernetes secret {#secret}
58+
1. Test the preflight checks by running them in a cluster using the preflight plugin and Helm CLI. For information about how to install the preflight plugin and run preflight checks, see [Run preflight checks for Helm installations](/vendor/preflight-running).
2059

21-
For Helm applications installed with Helm or KOTS v1.101.0 or later, define preflight checks in a Kubernetes Secret in your Helm chart `templates`. This allows you to define the preflights spec only one time to support running preflight checks in both Helm and KOTS installations.
60+
1. From the root directory of your Helm chart, package the chart into a `.tgz` archive:
2261

23-
Add the following YAML to a Kubernetes Secret in your Helm chart `templates` directory:
62+
```bash
63+
helm package --dependency-update .
64+
```
2465

25-
```yaml
26-
apiVersion: v1
27-
kind: Secret
28-
metadata:
29-
labels:
30-
troubleshoot.sh/kind: preflight
31-
name: "{{ .Release.Name }}-preflight-config"
32-
stringData:
33-
preflight.yaml: |
34-
apiVersion: troubleshoot.sh/v1beta2
35-
kind: Preflight
36-
metadata:
37-
name: preflight-sample
38-
spec:
39-
collectors: []
40-
analyzers: []
41-
```
66+
1. Add the chart archive to a new release. Promote the release to an internal development channel, and install the release in a development environment to test your changes.
4267

43-
As shown above, the Secret must include the following:
68+
## (Optional) Block installation with required (strict) preflights {#strict}
4469

45-
* The label `troubleshoot.sh/kind: preflight`
46-
* A `stringData` field with a key named `preflight.yaml` so that the preflight binary can use this Secret when it runs from the CLI
70+
For applications installed with a Replicated installer (Embedded Cluster, KOTS, kURL), you can set any preflight analyzer to `strict: true`. When you set `strict: true`, any `fail` outcomes for the analyzer block the deployment of the release.
4771

48-
### Preflight custom resource {#preflight-cr}
72+
:::note
73+
Troubleshoot ignores strict preflight analyzers if the `exclude` property is also included and evaluates to `true`. See [exclude](https://troubleshoot.sh/docs/analyze/#exclude) in the Troubleshoot documentation.
74+
:::
4975

50-
Define preflight checks in a Preflight custom resource for the following installation types:
51-
* Kubernetes manifest-based applications installed with any version of KOTS
52-
* Helm applications installed with KOTS v1.100.3 and earlier
53-
:::note
54-
For Helm charts installed with KOTS v1.101.0 and later, Replicated recommends that you define preflight checks in a Secret in the Helm chart `templates` instead of using the Preflight custom resource. See [Create a Secret](#secret) above.
76+
The following image shows how a `fail` outcome appears when you set `strict: true` on an analyzer, which prevents installation from continuing if the preflight check fails:
5577

56-
In KOTS v1.101.0 and later, preflights defined in the Helm chart override the Preflight custom resource used by KOTS. During installation, if KOTS v1.101.0 and later cannot find preflights specified in the Helm chart archive, then KOTS searches for `kind: Preflight` in the root of the release.
57-
:::
78+
![Preflight checks in Admin Console showing fail message with strict mode](/images/preflight-mysql-fail-strict.png)
79+
80+
[View a larger version of this image](/images/preflight-mysql-fail-strict.png)
5881

59-
Add the following YAML to a new file in a release:
82+
## Define preflights for non-Helm applications or KOTS v1.100.3 and earlier
83+
84+
For non-Helm applications or installations with KOTS v1.100.3 and earlier, add the Preflight custom resource to a YAML file at the root level of your release:
6085

6186
```yaml
87+
# preflights.yaml
88+
6289
apiVersion: troubleshoot.sh/v1beta2
6390
kind: Preflight
6491
metadata:
@@ -68,49 +95,4 @@ spec:
6895
analyzers: []
6996
```
7097

71-
For more information about the Preflight custom resource, see [Preflight and Support Bundle](/reference/custom-resource-preflight).
72-
73-
## Step 2: Define collectors and analyzers
74-
75-
This section describes how to define collectors and analyzers for preflight checks based on your application needs. You add the collectors and analyzers that you want to use in the `spec.collectors` and `spec.analyzers` keys in the manifest file that you created.
76-
77-
### Collectors
78-
79-
Collectors gather information from the cluster, the environment, the application, or other sources. Collectors generate output that is then used by the analyzers that you define to generate results for the preflight checks.
80-
81-
The following default collectors are included automatically to gather information about the cluster and cluster resources:
82-
* [clusterInfo](https://troubleshoot.sh/docs/collect/cluster-info/)
83-
* [clusterResources](https://troubleshoot.sh/docs/collect/cluster-resources/)
84-
85-
You do not need manually include the `clusterInfo` or `clusterResources` collectors in the specification. To use only the `clusterInfo` and `clusterResources` collectors, delete the `spec.collectors` key from the preflight specification.
86-
87-
The Troubleshoot open source project includes several additional collectors that you can include in the specification to gather more information from the installation environment. To view all the available collectors, see [All Collectors](https://troubleshoot.sh/docs/collect/all/) in the Troubleshoot documentation.
88-
89-
### Analyzers
90-
91-
Analyzers use the output from the collectors to generate results for the preflight checks, including the criteria for pass, fail, and warn outcomes and custom messages for each outcome.
92-
93-
For example, in a preflight check that checks the version of Kubernetes running in the target cluster, the analyzer can define a fail outcome when the cluster is running a version of Kubernetes less than 1.25 that includes the following custom message to the user: `The application requires Kubernetes 1.25.0 or later, and recommends 1.27.0`.
94-
95-
The Troubleshoot open source project includes several analyzers that you can include in your preflight check specification. The following are some of the analyzers in the Troubleshoot project that use the default `clusterInfo` or `clusterResources` collectors:
96-
* [clusterPodStatuses](https://troubleshoot.sh/docs/analyze/cluster-pod-statuses/)
97-
* [clusterVersion](https://troubleshoot.sh/docs/analyze/cluster-version/)
98-
* [deploymentStatus](https://troubleshoot.sh/docs/analyze/deployment-status/)
99-
* [distribution](https://troubleshoot.sh/docs/analyze/distribution/)
100-
* [nodeResources](https://troubleshoot.sh/docs/analyze/node-resources/)
101-
* [statefulsetStatus](https://troubleshoot.sh/docs/analyze/stateful-set-status/)
102-
* [storageClass](https://troubleshoot.sh/docs/analyze/storage-class/)
103-
104-
To view all the available analyzers, see the [Analyze](https://troubleshoot.sh/docs/analyze/) section of the Troubleshoot documentation.
105-
106-
### Block installation with required (strict) preflights {#strict}
107-
108-
For applications installed with KOTS or Embedded Cluster, you can set any preflight analyzer to `strict: true`. When `strict: true` is set, any `fail` outcomes for the analyzer block the deployment of the release.
109-
110-
:::note
111-
Strict preflight analyzers are ignored if the `exclude` property is also included and evaluates to `true`. See [exclude](https://troubleshoot.sh/docs/analyze/#exclude) in the Troubleshoot documentation.
112-
:::
113-
114-
### Examples
115-
116-
For common examples of collectors and analyzers used in preflight checks, see [Examples of Preflight Specs](/vendor/preflight-examples).
98+
Customize the collectors and analyzers as desired.

0 commit comments

Comments
 (0)