Skip to content

Instantly share code, notes, and snippets.

@pbochynski
Last active August 13, 2024 11:26
Show Gist options
  • Save pbochynski/059a9c2308c764d1991b45855083343c to your computer and use it in GitHub Desktop.
Save pbochynski/059a9c2308c764d1991b45855083343c to your computer and use it in GitHub Desktop.
Static website configured by config map
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: default
data:
index.html: |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample NGINX Page</title>
<script src="index.js"></script>
</head>
<body>
<h1>Welcome to NGINX</h1>
<div id="data"></div>
</body>
</html>
index.js: |
document.addEventListener("DOMContentLoaded", function() {
fetch('data.json')
.then(response => response.json())
.then(data => {
document.getElementById("data").innerText = `${data.message} (Status: ${data.status})`;
});
});
data.json: |
{
"message": "Hello, this is a mock endpoint!",
"status": "success"
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: nginx-config-volume
mountPath: /usr/share/nginx/html
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment