1717 preset : microshift
1818 # memory: <In MiB, if you want to change from default>
1919 # cpus: < int, if you want to change from default>
20- # disk: <In GiB, if you want to change from default>
20+ # disk: <In GiB, if you want to change from default>
21+
22+ - name : Deploy, Wait, and Ping Kubernetes Service
23+ run : |
24+ echo "📦 Creating Kubernetes Deployment..."
25+ kubectl create deployment web-app --image=nginxdemos/hello:plain-text
26+
27+ # 3. Expose the deployment using a KUBERNETES SERVICE resource
28+ echo "🔌 Exposing deployment via a Kubernetes Service..."
29+ kubectl expose deployment web-app --type=NodePort --port=80 --target-port=80
30+
31+ # 4. Wait dynamically until the Pod backing the service is fully running
32+ echo "⏳ Waiting for Kubernetes Deployment rollout..."
33+ kubectl rollout status deployment/web-app --timeout=60s
34+
35+ # 5. Dynamically poll the Kubernetes Service endpoints until they are ready
36+ echo "⏳ Waiting for Service endpoints to link..."
37+ for i in {1..10}; do
38+ IPS=$(kubectl get endpoints web-app -o jsonpath='{.subsets[*].addresses[*].ip}')
39+ if [ ! -z "$IPS" ]; then
40+ echo "✅ Kubernetes Service endpoints are live: $IPS"
41+ break
42+ fi
43+ echo "Waiting for endpoints... ($i/10)"
44+ sleep 2
45+ done
46+
47+ # 6. Bridge the network: Port-forward the Kubernetes Service to the local runner
48+ echo "🔌 Routing Kubernetes Service traffic to localhost:8080..."
49+ kubectl port-forward service/web-app 8080:80 &
50+ sleep 3 # Give the background port-forward tunnel a moment to stabilize
51+
52+ # 7. Ping the Service endpoint using curl
53+ echo "📡 Pinging the Kubernetes Service..."
54+ RESPONSE=$(curl -s http://localhost:8080)
55+
56+ echo "📥 Response payload received from K8s:"
57+ echo "----------------------------------------"
58+ echo "$RESPONSE"
59+ echo "----------------------------------------"
60+
61+ # 8. Assert the response proves the Kubernetes Service worked
62+ if [[ "$RESPONSE" == *"Server"* || ! -z "$RESPONSE" ]]; then
63+ echo "🎉 Success! The Kubernetes Service successfully routed traffic to the application."
64+ else
65+ echo "❌ Error: Did not receive an expected response from the Kubernetes Service."
66+ exit 1
67+ fi
0 commit comments