adding echo pod container

This commit is contained in:
baschno
2024-12-19 15:39:37 +01:00
parent 4483b2fa8e
commit 77c155bdb8
7 changed files with 172 additions and 0 deletions

13
echo-pod/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM nginx:alpine
COPY ./html /usr/share/nginx/html
COPY pod_name.sh /usr/local/bin/pod_name.sh
RUN chmod +x /usr/local/bin/pod_name.sh
ENTRYPOINT [ "/usr/local/bin/pod_name.sh" ]
EXPOSE 80
CMD ["nginx", "-g", "daemon_off;"]

3
echo-pod/README.md Normal file
View File

@@ -0,0 +1,3 @@
Thanks to
https://github.com/anveshmuppeda/kubernetes/tree/main/dockerfiles/echo-pod
https://medium.com/@muppedaanvesh/building-an-echo-pod-to-display-kubernetes-pod-and-node-names-037801b27826

View File

@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: echopod
labels:
app: echopod
spec:
replicas: 2 # Number of pod replicas
selector:
matchLabels:
app: echopod
template:
metadata:
labels:
app: echopod
spec:
containers:
- name: echopod
image: bschnorbus/echo-pod
ports:
- containerPort: 80
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
---
apiVersion: v1
kind: Service
metadata:
name: echopod-service
spec:
type: NodePort # Change to LoadBalancer if using a cloud provider
ports:
- port: 80
targetPort: 80
nodePort: 30080 # Port to expose on the node
selector:
app: echopod

36
echo-pod/html/index.html Normal file
View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pod Info</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<!-- Logo and Kubernetes text -->
<div class="logo-container">
<img src="k8s-logo.png" alt="Kubernetes Logo" class="logo-img">
<span class="k8s-text">Kubernetes</span>
</div>
<!-- Information Box -->
<div class="info-box">
<!-- Welcome message -->
<div class="welcome-message">
Welcome from Echo Pod
</div>
<!-- Node name section -->
<div class="node-name">
Node Name: {{NODE_NAME}}
</div>
<!-- Pod name section -->
<div class="pod-name">
Pod Name: {{POD_NAME}}
</div>
</div>
</div>
</body>
</html>

BIN
echo-pod/html/k8s-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

66
echo-pod/html/style.css Normal file
View File

@@ -0,0 +1,66 @@
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
position: relative; /* Allow absolute positioning of the footer */
}
.container {
text-align: center;
}
.logo-container {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
.logo-img {
width: 100px; /* Adjust the logo size here */
margin-right: 10px; /* Space between the logo and text */
}
.k8s-text {
font-size: 65px;
font-weight: bold;
color: #007acc;
}
.info-box {
background-color: white; /* Background color of the box */
border: 2px solid #007acc; /* Border color */
border-radius: 8px; /* Rounded corners */
padding: 20px; /* Space inside the box */
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); /* Subtle shadow */
margin: 20px auto; /* Center the box with margin */
width: fit-content; /* Allow width to adjust based on content */
max-width: 90%; /* Max width to prevent overflow */
}
.welcome-message, .node-name, .pod-name {
font-size: 20px; /* Font size for all messages */
color: #333; /* Text color for contrast */
margin: 10px 0; /* Margin for spacing */
}
.welcome-message {
font-size: 20px; /* Font size for all messages */
font-weight: bold;
}
#footer {
font-size: 14px;
color: #666;
position: absolute; /* Change to absolute positioning */
bottom: 10px; /* Distance from the bottom */
left: 50%; /* Center horizontally */
transform: translateX(-50%); /* Adjust to center */
text-align: center; /* Center text inside footer */
font-style: italic;
}

15
echo-pod/pod_name.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Get hostname
POD_NAME=$(hostname)
POD_NAME=${POD_NAME:-"Unknown Pod Name"}
# Get node name
NODE_NAME=${NODE_NAME:-"Unknown Node Name"}
# Replace the placeholders in the HTML with the actual pod name and node name
sed -i "s/{{POD_NAME}}/${POD_NAME}/g" /usr/share/nginx/html/index.html
sed -i "s/{{NODE_NAME}}/${NODE_NAME}/g" /usr/share/nginx/html/index.html
# Start Nginx
nginx -g 'daemon off;'