Skip to content

Commit dd31167

Browse files
committed
first commit
0 parents  commit dd31167

File tree

6 files changed

+167
-0
lines changed

6 files changed

+167
-0
lines changed

.github/workflows/build.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI/CD Pipeline for Minikube Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# Step 1: Checkout the repository
17+
- name: Checkout Repository
18+
uses: actions/checkout@v3
19+
20+
# Step 2: Install Minikube
21+
- name: Install Minikube
22+
run: |
23+
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
24+
sudo install minikube-linux-amd64 /usr/local/bin/minikube
25+
26+
# Step 3: Start Minikube with Docker driver (on GitHub runner environment)
27+
- name: Start Minikube
28+
run: |
29+
minikube start --driver=docker
30+
31+
# Step 4: Wait for Minikube to be fully ready
32+
- name: Wait for Minikube to be ready
33+
run: |
34+
minikube status
35+
sleep 30 # Sleep for 30 seconds to ensure Minikube has fully started
36+
37+
# Step 5: Set up kubectl to use Minikube's config
38+
- name: Set up kubectl for Minikube
39+
run: |
40+
mkdir -p $HOME/.kube
41+
minikube kubectl -- get pods # This ensures that kubectl is working and the kubeconfig is set up
42+
43+
# Step 6: Apply Kubernetes Manifests for the Nginx application
44+
- name: Apply Kubernetes Manifests
45+
run: |
46+
kubectl apply -f ./hello-world-nginx-deployment.yaml
47+
48+
# Step 7: Verify the Deployment
49+
- name: Verify Deployment
50+
run: |
51+
kubectl rollout status deployment/hello-world-nginx
52+
kubectl get svc hello-world-nginx

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx:latest
2+
COPY index.html /usr/share/nginx/html/index.html

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# install-miniqube-with-github-action
2+
install-miniqube-with-github-action

hello-world-nginx-deployment.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hello-world-nginx
5+
labels:
6+
app: hello-world-nginx
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: hello-world-nginx
12+
template:
13+
metadata:
14+
labels:
15+
app: hello-world-nginx
16+
spec:
17+
containers:
18+
- name: hello-world-nginx
19+
image: bhartineha/hello-world-nginx:latest
20+
ports:
21+
- containerPort: 80
22+
---
23+
apiVersion: v1
24+
kind: Service
25+
metadata:
26+
name: hello-world-nginx
27+
spec:
28+
selector:
29+
app: hello-world-nginx
30+
ports:
31+
- protocol: TCP
32+
port: 80
33+
targetPort: 80
34+
type: NodePort

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello World</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
</body>
9+
</html>

install_minikube.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)