Created
March 27, 2025 15:49
-
-
Save AlexsJones/4764121871d4012a471aa9a837046333 to your computer and use it in GitHub Desktop.
try k8sgpt with kind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Default values, can be overridden with environment variables or command-line args | |
| KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-k8sgpt-cluster}" | |
| HELM_RELEASE_NAME="${HELM_RELEASE_NAME:-k8sgpt}" | |
| NAMESPACE="${NAMESPACE:-k8sgpt}" | |
| OPENAI_TOKEN="${OPENAI_TOKEN:-}" | |
| # Check for OpenAI token | |
| if [[ -z "$OPENAI_TOKEN" ]]; then | |
| echo "OPENAI_TOKEN is not defined. Please provide the token as an argument or set it as an environment variable." | |
| exit 1 | |
| fi | |
| # Function to check if a command is installed | |
| check_command() { | |
| if ! command -v "$1" &> /dev/null; then | |
| echo "$1 is not installed. Please install $1 and try again." | |
| exit 1 | |
| fi | |
| } | |
| # Main script logic | |
| main() { | |
| check_command kind | |
| check_command helm | |
| check_command kubectl | |
| echo "Creating kind cluster..." | |
| kind create cluster --name "$KIND_CLUSTER_NAME" | |
| echo "Adding k8sgpt helm repo..." | |
| helm repo add k8sgpt https://charts.k8sgpt.ai/ | |
| helm repo update | |
| echo "Installing k8sgpt-operator helm chart..." | |
| if helm status "$HELM_RELEASE_NAME" -n "$NAMESPACE" &> /dev/null; then | |
| echo "k8sgpt-operator is already installed. Skipping installation." | |
| else | |
| helm install "$HELM_RELEASE_NAME" k8sgpt/k8sgpt-operator -n "$NAMESPACE" --create-namespace --set interplex.enabled=true | |
| fi | |
| echo "Creating secret..." | |
| if kubectl get secret k8sgpt-sample-secret -n "$NAMESPACE" -o jsonpath="{.data}" &> /dev/null; then | |
| echo "Secret k8sgpt-sample-secret already exists in namespace $NAMESPACE. Skipping creation." | |
| else | |
| kubectl create secret generic k8sgpt-sample-secret --from-literal=openai-api-key="$OPENAI_TOKEN" -n "$NAMESPACE" | |
| fi | |
| echo "Applying valid_k8sgpt_remediation_sample.yaml..." | |
| kubectl apply -f valid_k8sgpt_remediation_with_interplex.yaml -n "$NAMESPACE" | |
| echo "Applying deployment_missing_image.yaml..." | |
| kubectl apply -f deployment_missing_image.yaml | |
| echo "k8sgpt local setup complete." | |
| } | |
| # Execute the main function, passing any command-line arguments. | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment