diff --git a/echo-pod/Dockerfile b/echo-pod/Dockerfile new file mode 100644 index 0000000..8fc4691 --- /dev/null +++ b/echo-pod/Dockerfile @@ -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;"] \ No newline at end of file diff --git a/echo-pod/README.md b/echo-pod/README.md new file mode 100644 index 0000000..15b1ce7 --- /dev/null +++ b/echo-pod/README.md @@ -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 \ No newline at end of file diff --git a/echo-pod/echo-pod-deployment/echo-pod-deployment.yaml b/echo-pod/echo-pod-deployment/echo-pod-deployment.yaml new file mode 100644 index 0000000..4d1ba94 --- /dev/null +++ b/echo-pod/echo-pod-deployment/echo-pod-deployment.yaml @@ -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 \ No newline at end of file diff --git a/echo-pod/html/index.html b/echo-pod/html/index.html new file mode 100644 index 0000000..a8eb2cf --- /dev/null +++ b/echo-pod/html/index.html @@ -0,0 +1,36 @@ + + + + + + Pod Info + + + +
+ +
+ Kubernetes Logo + Kubernetes +
+ + +
+ +
+ Welcome from Echo Pod +
+ + +
+ Node Name: {{NODE_NAME}} +
+ + +
+ Pod Name: {{POD_NAME}} +
+
+
+ + \ No newline at end of file diff --git a/echo-pod/html/k8s-logo.png b/echo-pod/html/k8s-logo.png new file mode 100644 index 0000000..6703739 Binary files /dev/null and b/echo-pod/html/k8s-logo.png differ diff --git a/echo-pod/html/style.css b/echo-pod/html/style.css new file mode 100644 index 0000000..de2552c --- /dev/null +++ b/echo-pod/html/style.css @@ -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; +} \ No newline at end of file diff --git a/echo-pod/pod_name.sh b/echo-pod/pod_name.sh new file mode 100644 index 0000000..0b9c9af --- /dev/null +++ b/echo-pod/pod_name.sh @@ -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;'