Created
April 20, 2022 13:01
-
-
Save mikamboo/a02d7c00eb81fea2c06c273dc43581d9 to your computer and use it in GitHub Desktop.
Kubectl create nodejs app to echo headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: nodejs-app | |
labels: | |
app: nodejs-app | |
data: | |
server.js: | | |
const http = require("http"); | |
const host = '0.0.0.0'; | |
const port = 8080; | |
const requestListener = function (req, res) { | |
//console.log(req) | |
res.setHeader("Content-Type", "application/json"); | |
res.writeHead(200); | |
res.end(JSON.stringify(req.headers, null, 3)); | |
//res.setHeader("Content-Type", "text/html"); | |
//res.end(`<html><body><h1>This is HTML !!!</h1></body></html>`); | |
}; | |
const server = http.createServer(requestListener); | |
server.listen(port, host, () => { | |
console.log(`Server is running on http://${host}:${port}`); | |
}); | |
--- | |
kind: Deployment | |
apiVersion: apps/v1 | |
metadata: | |
name: nodejs-app | |
labels: | |
app: nodejs-app | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: nodejs-app | |
template: | |
metadata: | |
labels: | |
app: nodejs-app | |
spec: | |
volumes: | |
- name: nodejs-app | |
configMap: | |
name: nodejs-app | |
items: | |
- key: server.js | |
path: server.js | |
containers: | |
- name: nodejs-app | |
env: | |
- name: APP | |
value: nodejs | |
- name: NODE_DEBUG | |
value: http | |
volumeMounts: | |
- name: nodejs-app | |
mountPath: /app | |
readOnly: false | |
imagePullPolicy: Always | |
ports: | |
- name: web | |
containerPort: 8080 | |
image: node:14-alpine | |
#command: ["/bin/sh", "-ec", "sleep infinity"] | |
command: ["/usr/local/bin/node", "/app/server.js"] | |
livenessProbe: | |
httpGet: | |
path: /healthz | |
port: 8080 | |
resources: | |
limits: | |
cpu: 200m | |
memory: 256Mi | |
requests: | |
cpu: 100m | |
memory: 128Mi | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: nodejs-app | |
labels: | |
app: nodejs-app | |
spec: | |
ports: | |
- protocol: TCP | |
name: web | |
port: 80 | |
targetPort: 8080 | |
selector: | |
app: nodejs-app | |
--- | |
apiVersion: traefik.containo.us/v1alpha1 | |
kind: IngressRoute | |
metadata: | |
name: nodejs-app | |
labels: | |
app: nodejs-app | |
spec: | |
entryPoints: | |
- web | |
- websecure | |
routes: | |
- match: Host(`my.nodejs.app`) && PathPrefix(`/`) | |
kind: Rule | |
services: | |
- name: nodejs-app | |
port: 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment