EGS Preflight Check Script
A robust preflight check script designed for EGS setup on Kubernetes. This script verifies Kubernetes resource configurations, permissions, and connectivity to ensure the environment is ready for deployment.
Features
- π οΈ Resource Validation: Checks namespaces, services, PVCs, and privileges.
- π Comprehensive Preflight Checks: Validates Kubernetes configurations and access.
- π Internet Connectivity Checks: Ensures cluster access to external resources.
- π§Ή Resource Cleanup: Optionally deletes created resources after validation.
- β‘ Multi-context Support: Operates on multiple Kubernetes contexts.
- π Debugging: Provides detailed logs for troubleshooting.
Usage
./egs-preflight-check.sh [OPTIONS]
Multi Cluster Example
./egs-preflight-check.sh \
--kubeconfig ~/.kube/config \
--kubecontext-list context1,context2
Key Options:
| Option | Description |
|---|---|
--namespace-to-check |
ποΈ Comma-separated list of namespaces to check existence. |
--test-namespace |
π·οΈ Namespace for test creation and deletion (default: egs-test-namespace). |
--pvc-test-namespace |
π Namespace for PVC test creation and deletion (default: egs-test-namespace). |
--pvc-name |
π οΈ Name of the test PVC (default: egs-test-pvc). |
--storage-class |
ποΈ Storage class for the PVC (default: none). |
--storage-size |
π¦ Storage size for the PVC (default: 1Gi). |
--service-name |
π Name of the test service (default: test-service). |
--service-type |
βοΈ Type of service to create and validate (ClusterIP, NodePort, LoadBalancer, or all). Default: all. |
--kubeconfig |
ποΈ Path to the kubeconfig file (mandatory). |
--kubecontext |
π Context from the kubeconfig file (mandatory). |
--kubecontext-list |
π Comma-separated list of context names to operate on. |
--cleanup |
π§Ή Whether to delete test resources (true or false). Default: true. |
--global-wait |
β³ Time to wait after each command execution (default: 0). |
--watch-resources |
π Enable or disable watching resources after creation (default: false). |
--watch-duration |
β±οΈ Duration to watch resources after creation (default: 30 seconds). |
--invoke-wrappers |
π οΈ Comma-separated list of wrapper functions to invoke. |
--display-resources |
ποΈ Whether to display resources created (default: true). |
--kubectl-path |
β‘ Override default kubectl binary path. |
--function-debug-input |
π Enable or disable function debugging (default: false). |
--generate-summary |
π Enable or disable summary generation (default: true). |
--resource-action-pairs |
π Override default resource-action pairs (e.g., pod:create,service:get). |
--fetch-resource-names |
π Fetch all resource names from the cluster (default: false). |
--fetch-webhook-names |
π Fetch all webhook names from the cluster (default: false). |
--api-resources |
π Comma-separated list of API resources to include or operate on. |
--webhooks |
π Comma-separated list of webhooks to include or operate on. |
--help |
β Display this help message. |
Default Resource-Action Pairs:
π The default resource-action pairs used for privilege checks are:
namespace:create,namespace:delete,namespace:get,namespace:list,namespace:watchpod:create,pod:delete,pod:get,pod:list,pod:watchservice:create,service:delete,service:get,service:list,service:watchconfigmap:create,configmap:delete,configmap:get,configmap:list,configmap:watchsecret:create,secret:delete,secret:get,secret:list,secret:watchserviceaccount:create,serviceaccount:delete,serviceaccount:get,serviceaccount:list,serviceaccount:watchclusterrole:create,clusterrole:delete,clusterrole:get,clusterrole:listclusterrolebinding:create,clusterrolebinding:delete,clusterrolebinding:get,clusterrolebinding:list
Wrapper Functions:
| Wrapper Function | Description |
|---|---|
ποΈ namespace_preflight_checks |
Validates namespace creation and existence. |
π grep_k8s_resources_with_crds_and_webhooks |
Validates existing resources available in the cluster based on resource names. (e.g., prometheus, gpu-operator, postgresql) |
π pvc_preflight_checks |
Validates PVC creation, deletion, and storage properties. |
βοΈ service_preflight_checks |
Validates the creation and deletion of services (ClusterIP, NodePort, LoadBalancer). |
π k8s_privilege_preflight_checks |
Validates privileges for Kubernetes actions on resources. |
π internet_access_preflight_checks |
Validates internet connectivity from within the Kubernetes cluster. |
Examples
./egs-preflight-check.sh --namespace-to-check my-namespace --test-namespace test-ns --invoke-wrappers namespace_preflight_checks
./egs-preflight-check.sh --pvc-test-namespace pvc-ns --pvc-name test-pvc --storage-class standard --storage-size 1Gi --invoke-wrappers pvc_preflight_checks
./egs-preflight-check.sh --test-namespace service-ns --service-name test-service --service-type NodePort --watch-resources true --watch-duration 60 --invoke-wrappers service_preflight_checks
./egs-preflight-check.sh --invoke-wrappers namespace_preflight_checks,pvc_preflight_checks,service_preflight_checks
./egs-preflight-check.sh --resource-action-pairs pod:create,namespace:delete --invoke-wrappers k8s_privilege_preflight_checks
./egs-preflight-check.sh --function-debug-input true --invoke-wrappers namespace_preflight_checks
./egs-preflight-check.sh --generate-summary false --invoke-wrappers namespace_preflight_checks
./egs-preflight-check.sh --fetch-resource-names true --invoke-wrappers service_preflight_checks
./egs-preflight-check.sh --api-resources pod,service --invoke-wrappers namespace_preflight_checks
Note: If no wrapper function is specified, all preflight check functions will be executed by default.
Sample Output
- π Logs: Detailed logs are generated for each step, including successes and failures.
- π Summary: A final summary is displayed, highlighting the status of all checks.
β οΈ Important: Interpreting Preflight Check Results
π Review Failures Before Proceeding: After running the preflight check script, carefully review any failures or warnings in the output. These issues should be addressed before proceeding with EGS installation to ensure a smooth deployment process.
π Understanding Check Requirements: Not all preflight checks may be required to pass depending on your specific setup and requirements:
- π΄ Critical Failures: Must be resolved before proceeding (e.g., namespace creation permissions, basic Kubernetes access) and may be ignored if not applicable.
- π‘ Warnings: Review and resolve if they impact your specific use case and can be ignored if not applicable
- π’ Optional Checks: Checks are passing for your deployment scenario
π‘ Examples of Setup-Dependent Checks:
- Storage Class Checks: May fail if you donβt need persistent storage
- Service Type Checks: LoadBalancer services may not be available in all environments
- Internet Connectivity: May not be required for air-gapped deployments
- Resource Quotas: May not apply if your cluster doesnβt use resource quotas
π Next Steps:
- Review the summary to identify failed checks
- Analyze failures to understand their impact on your deployment
- Resolve critical issues that affect basic functionality
- Evaluate optional failures based on your specific requirements
- Re-run checks after resolving issues to verify fixes
π Detailed Logs for Troubleshooting:
The preflight check script generates a comprehensive log file egs-preflight-check-output.log that contains:
- Detailed execution logs for each check performed
- Command outputs and error messages
- Resource creation/deletion details for test resources
- Permission check results with specific failure reasons
- Timing information for performance analysis
- Context-specific details for multi-cluster setups
π Using the Log File:
- Location: Generated in the same directory as the script
- Format: Human-readable with timestamps and clear section separators
- Search: Use
grepto find specific failures (e.g.,grep -i "fail\|error" egs-preflight-check-output.log) - Debugging: Enable
--function-debug-input truefor additional verbose logging - Retention: Logs are preserved between runs for comparison and analysis
Related Files
egs-preflight-check.sh: The main preflight check scriptegs-preflight-check-output.log: Detailed execution logs and troubleshooting information- Test Resources: Temporary namespaces, services, and PVCs created during checks (cleaned up by default)