-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (74 loc) · 3.46 KB
/
Copy pathcrc.yml
File metadata and controls
89 lines (74 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Deploy Standalone OpenShift 4 Cluster
on:
workflow_dispatch: # Allows manual trigger from GitHub UI
jobs:
openshift-local:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- flavor: okd
node-name: crc
- flavor: microshift
node-name: api.crc.testing
- flavor: openshift
node-name: crc
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up CRC
uses: crc-org/crc-github-action@v1
with:
pull-secret: ${{ secrets.OPENSHIFT_PULL_SECRET }}
preset: ${{ matrix.flavor }}
#memory: <In MiB, if you want to change from default>
#cpus: < int, if you want to change from default>
#disk: <In GiB, if you want to change from default>
- name: Deploy, Wait, and Ping Kubernetes Service
run: |
echo "Check what it has been deployed ..."
echo "Node information"
kubectl get node
echo "============================"
kubectl describe node/${{ matrix.node-name }}
echo "List of pods ...."
kubectl get pods -A
echo "List of namespaces ...."
kubectl get ns
echo "📦 Creating Kubernetes Deployment..."
kubectl create deployment web-app --image=nginxdemos/hello:plain-text
# 3. Expose the deployment using a KUBERNETES SERVICE resource
echo "🔌 Exposing deployment via a Kubernetes Service..."
kubectl expose deployment web-app --type=NodePort --port=80 --target-port=80
# 4. Wait dynamically until the Pod backing the service is fully running
echo "⏳ Waiting for Kubernetes Deployment rollout..."
kubectl rollout status deployment/web-app --timeout=60s
# 5. Dynamically poll the Kubernetes Service endpoints until they are ready
echo "⏳ Waiting for Service endpoints to link..."
for i in {1..10}; do
IPS=$(kubectl get endpointslice -l kubernetes.io/service-name=web-app -o jsonpath='{.items[*].endpoints[*].addresses[0]}')
if [ ! -z "$IPS" ]; then
echo "✅ Kubernetes Service endpoints are live: $IPS"
break
fi
echo "Waiting for endpoints... ($i/10)"
sleep 2
done
# 6. Bridge the network: Port-forward the Kubernetes Service to the local runner
echo "🔌 Routing Kubernetes Service traffic to localhost:8080..."
kubectl port-forward service/web-app 8080:80 &
sleep 3 # Give the background port-forward tunnel a moment to stabilize
# 7. Ping the Service endpoint using curl
echo "📡 Pinging the Kubernetes Service..."
RESPONSE=$(curl -s http://localhost:8080)
echo "📥 Response payload received from K8s:"
echo "----------------------------------------"
echo "$RESPONSE"
echo "----------------------------------------"
# 8. Assert the response proves the Kubernetes Service worked
if [[ "$RESPONSE" == *"Server"* || ! -z "$RESPONSE" ]]; then
echo "🎉 Success! The Kubernetes Service successfully routed traffic to the application."
else
echo "❌ Error: Did not receive an expected response from the Kubernetes Service."
exit 1
fi