Skip to content

Commit 1b6e5c6

Browse files
committed
added solution of challenge12
1 parent e6accd7 commit 1b6e5c6

9 files changed

Lines changed: 736 additions & 0 deletions

File tree

challenge12/docker/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM httpd:2.4
2+
RUN echo "<h1> It is working on $(hostname)" > /usr/local/apache2/htdocs/index.html
3+
WORKDIR /usr/local/apache2/htdocs/health
4+
COPY /health .
5+
WORKDIR /usr/local/apache2/conf
6+
COPY ./httpd.conf .
7+
COPY ./server.conf .
8+
RUN chmod a+x /usr/local/apache2/htdocs/
9+
EXPOSE 80
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OK
2+

challenge12/docker/httpd.conf

Lines changed: 549 additions & 0 deletions
Large diffs are not rendered by default.

challenge12/docker/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>it is working on localhost.localdomain

challenge12/docker/server.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /usr/local/apache2/htdocs
3+
4+
<Directory /usr/local/apache2/htdocs>
5+
Options FollowSymLinks
6+
</Directory>
7+
<Location /health>
8+
# Disable entity tags (ETags)
9+
FileETag None
10+
11+
# Force expiration headers to ensure freshness
12+
Header always set Cache-Control "no-store, no-cache, must-revalidate"
13+
Header always set Pragma "no-cache"
14+
Header always set Expires "0"
15+
16+
Require all granted
17+
</Location>
18+
</VirtualHost>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: my-deployment
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: my-deployment
10+
template:
11+
metadata:
12+
labels:
13+
app: my-deployment
14+
spec:
15+
containers:
16+
- name: my-container
17+
image: challenge12:latest
18+
imagePullPolicy: IfNotPresent
19+
ports:
20+
- containerPort: 80
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: my-ingress
5+
spec:
6+
rules:
7+
- host: app.example.com
8+
http:
9+
paths:
10+
- pathType: Prefix
11+
path: "/"
12+
backend:
13+
service:
14+
name: web-app-service
15+
port:
16+
number: 80
17+
- pathType: Prefix
18+
path: "/admin"
19+
backend:
20+
service:
21+
name: admin-service
22+
port:
23+
number: 80
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: web-app-service
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: my-deployment
9+
ports:
10+
- port: 80
11+
nodePort: 30080
12+
targetPort: 80

challenge12/readme.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Challenge 12: Advanced Networking and Ingress 🌐
2+
Objective: Introduce an Ingress resource to manage external access, replacing the basic NodePort service and enabling path-based routing.
3+
4+
## The Scenario
5+
Your current NodePort Service works, but it exposes the application on a high, random port (or port 30080) and doesn't handle proper routing or SSL termination. You need to transition to an Ingress object to manage external HTTP/S access via a standard web address.
6+
7+
Assume you have an Ingress Controller (like NGINX Ingress Controller) already running in your cluster.
8+
9+
## The Challenge
10+
Write a single YAML manifest (ingress.yaml) that defines an Ingress resource for your application based on the following rules:
11+
12+
Host and Name: The Ingress should be named web-app-ingress and handle traffic for the host app.example.com.
13+
14+
Service Mapping: It must route all traffic coming to app.example.com to the Service you created in Challenge 6 (web-app-service) on port 80.
15+
16+
Path Routing: Implement two distinct path rules:
17+
18+
Requests to the root path (/) should be directed to the web-app-service.
19+
20+
Requests to the path /admin should be directed to a separate, conceptual service named admin-service (also on port 80).
21+
22+
## Your Deliverable:
23+
The complete, single YAML manifest file (ingress.yaml) for the Ingress resource.
24+
25+
## Solution
26+
27+
In order to create an ingress we need to create a service pointing to a deployment running inside a container inside a pod using a config something like follwing
28+
29+
```yaml
30+
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
name: web-app-service
35+
spec:
36+
type: NodePort
37+
selector:
38+
app: my-deployment
39+
ports:
40+
- port: 80
41+
nodePort: 30080
42+
targetPort: 80
43+
44+
```
45+
46+
47+
also we need a deployment which this service's nodePort refer to
48+
```yaml
49+
50+
apiVersion: apps/v1
51+
kind: Deployment
52+
metadata:
53+
name: my-deployment
54+
spec:
55+
replicas: 1
56+
selector:
57+
matchLabels:
58+
app: my-deployment
59+
template:
60+
metadata:
61+
labels:
62+
app: my-deployment
63+
spec:
64+
containers:
65+
- name: my-container
66+
image: challenge12:latest
67+
imagePullPolicy: IfNotPresent
68+
ports:
69+
- containerPort: 80
70+
71+
```
72+
73+
74+
lastly we can create our ingress pointing to the services which we have created providing it DNS using configuration smoething like below
75+
76+
```yaml
77+
78+
apiVersion: networking.k8s.io/v1
79+
kind: Ingress
80+
metadata:
81+
name: my-ingress
82+
spec:
83+
rules:
84+
- host: app.example.com
85+
http:
86+
paths:
87+
- pathType: Prefix
88+
path: "/"
89+
backend:
90+
service:
91+
name: web-app-service
92+
port:
93+
number: 80
94+
- pathType: Prefix
95+
path: "/admin"
96+
backend:
97+
service:
98+
name: admin-service
99+
port:
100+
number: 80
101+
102+
```

0 commit comments

Comments
 (0)