Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is the repository for the scenarios available on [killercoda.com/kubernetes
* StatefulSet
* kubectl intro
* kubectl contexts
* ...
* Kubernetes troubleshooting scenario

## Contribute

Expand Down
1 change: 1 addition & 0 deletions application-troubleshooting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Troubleshoot application not accessible due to Secret misconfiguration and Service port mismatch
37 changes: 37 additions & 0 deletions application-troubleshooting/app-not-accessible/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Troubleshoot Application Not Accessible in Kubernetes

An application has been deployed to the Kubernetes cluster, but it is not accessible.

Although all required resources exist, the application is not functioning as expected.

Your task is to investigate and fix the issues step by step.

---

## Observed Problems

- The backend pod is stuck in `CrashLoopBackOff`
- A Service exists for the application
- Accessing the application through the Service fails

---

## Tasks

1. Investigate why the pod is crashing and fix the issue.
2. Ensure the pod reaches the `Running` state.
3. Investigate why the Service is not routing traffic correctly.
4. Fix the Service configuration so the application becomes accessible.

---

## Useful Commands

```bash
kubectl get pods -n app-demo
kubectl describe pod <pod-name> -n app-demo
kubectl logs <pod-name> -n app-demo

kubectl get svc -n app-demo
kubectl describe svc backend-svc -n app-demo
kubectl port-forward svc/backend-svc 8080:80 -n app-demo
57 changes: 57 additions & 0 deletions application-troubleshooting/app-not-accessible/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#! /bin/bash
set -e
kubectl create namespace app-demo || true

kubectl apply -n app-demo -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
stringData:
DB_PASSWORD: supersecret
EOF

kubectl apply -n app-demo -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: hashicorp/http-echo
args:
- "-text=Backend running"
- "-listen=:8080"
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: app-secret
key: DB_PASS
ports:
- containerPort: 8080
EOF

kubectl apply -n app-demo -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: backend-svc
spec:
selector:
app: backend
ports:
- port: 80
targetPort: 80
EOF
26 changes: 26 additions & 0 deletions application-troubleshooting/app-not-accessible/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

NAMESPACE="app-demo"
APP_LABEL="backend"
SERVICE_NAME="backend-svc"

# 1) Verify the backend pod is Running
POD_PHASE=$(kubectl get pods -n "$NAMESPACE" -l app="$APP_LABEL" \
-o jsonpath='{.items[0].status.phase}')

if [ "$POD_PHASE" != "Running" ]; then
echo "❌ Backend pod is not running. Current phase: $POD_PHASE"
exit 1
fi

# 2) Verify the Service targetPort is correctly set to 8080
TARGET_PORT=$(kubectl get svc "$SERVICE_NAME" -n "$NAMESPACE" \
-o jsonpath='{.spec.ports[0].targetPort}')

if [ "$TARGET_PORT" != "8080" ]; then
echo "❌ Service targetPort is incorrect. Expected 8080, got $TARGET_PORT"
exit 1
fi

echo "✅ Application is running and Service is configured correctly."