|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | +import os |
| 4 | + |
| 5 | +def run_command(command, capture_output=False, check=True): |
| 6 | + """Runs a shell command and returns the output.""" |
| 7 | + try: |
| 8 | + result = subprocess.run( |
| 9 | + command, |
| 10 | + shell=True, |
| 11 | + check=check, |
| 12 | + capture_output=capture_output, |
| 13 | + text=True |
| 14 | + ) |
| 15 | + if capture_output: |
| 16 | + return result.stdout.strip() |
| 17 | + except subprocess.CalledProcessError as e: |
| 18 | + print(f"Error: Command failed with return code {e.returncode}\n{e.stderr}") |
| 19 | + sys.exit(1) |
| 20 | + |
| 21 | +def install_dependencies(): |
| 22 | + """Installs necessary dependencies.""" |
| 23 | + print("Installing dependencies...") |
| 24 | + run_command("sudo apt-get update") |
| 25 | + run_command("sudo apt-get install -y curl wget apt-transport-https conntrack") |
| 26 | + |
| 27 | +def install_minikube(): |
| 28 | + """Downloads and installs Minikube.""" |
| 29 | + print("Installing Minikube...") |
| 30 | + minikube_latest_url = "https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64" |
| 31 | + run_command(f"wget -O minikube {minikube_latest_url}") |
| 32 | + run_command("sudo install minikube /usr/local/bin/") |
| 33 | + os.remove("minikube") # Clean up the downloaded binary |
| 34 | + |
| 35 | +def install_kubectl(): |
| 36 | + """Installs kubectl for interacting with the Kubernetes cluster.""" |
| 37 | + print("Installing kubectl...") |
| 38 | + kubectl_latest_url = "https://storage.googleapis.com/kubernetes-release/release/stable.txt" |
| 39 | + latest_version = run_command(f"curl -s {kubectl_latest_url}", capture_output=True) |
| 40 | + kubectl_binary_url = f"https://storage.googleapis.com/kubernetes-release/release/{latest_version}/bin/linux/amd64/kubectl" |
| 41 | + run_command(f"curl -LO {kubectl_binary_url}") |
| 42 | + run_command("sudo install kubectl /usr/local/bin/") |
| 43 | + os.remove("kubectl") # Clean up the downloaded binary |
| 44 | + |
| 45 | +def start_minikube(): |
| 46 | + """Starts Minikube with a single-node cluster.""" |
| 47 | + print("Starting Minikube...") |
| 48 | + run_command("minikube start --driver=docker") |
| 49 | + |
| 50 | +def verify_installation(): |
| 51 | + """Verifies the Minikube installation.""" |
| 52 | + print("Verifying Minikube installation...") |
| 53 | + minikube_version = run_command("minikube version", capture_output=True) |
| 54 | + kubectl_version = run_command("kubectl version --client=true --short", capture_output=True) |
| 55 | + print(f"Minikube installed successfully: {minikube_version}") |
| 56 | + print(f"kubectl installed successfully: {kubectl_version}") |
| 57 | + |
| 58 | +def main(): |
| 59 | + print("Starting Minikube installation...") |
| 60 | + install_dependencies() |
| 61 | + install_minikube() |
| 62 | + install_kubectl() |
| 63 | + start_minikube() |
| 64 | + verify_installation() |
| 65 | + print("Minikube single-node cluster setup completed successfully.") |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + main() |
0 commit comments