Instantly share code, notes, and snippets.

Embed
What would you like to do?
ConfigMaps and Secrets with Kubernetes
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
FROM node:6-onbuild
EXPOSE 3000
ENV LANGUAGE English
ENV API_KEY 123-456-789
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: envtest
spec:
replicas: 1
template:
metadata:
labels:
name: envtest
spec:
containers:
- name: envtest
image: gcr.io/<PROJECT_ID>/envtest
ports:
- containerPort: 3000
env:
- name: LANGUAGE
value: "English"
- name: API_KEY
value: "123-456-789"
// Copyright 2017, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License")
var http = require('http');
var server = http.createServer(function (request, response) {
const language = process.env.LANGUAGE;
const API_KEY = process.env.API_KEY;
response.write(`Language: ${language}\n`);
response.write(`API Key: ${API_KEY}\n`);
response.end(`\n`);
});
server.listen(3000);
// Copyright 2017, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License")
var http = require('http');
var fs = require('fs');
var server = http.createServer(function (request, response) {
fs.readFile('./config/config.json', function (err, config) {
if (err) return console.log(err);
const language = JSON.parse(config).LANGUAGE;
fs.readFile('./secret/secret.json', function (err, secret) {
if (err) return console.log(err);
const API_KEY = JSON.parse(secret).API_KEY;
response.write(`Language: ${language}\n`);
response.write(`API Key: ${API_KEY}\n`);
response.end(`\n`);
});
});
});
server.listen(3000);
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: envtest
spec:
replicas: 1
template:
metadata:
labels:
name: envtest
spec:
containers:
- name: envtest
image: gcr.io/smart-spark-93622/envtest:file5
ports:
- containerPort: 3000
volumeMounts:
- name: my-config
mountPath: /usr/src/app/config
- name: my-secret
mountPath: /usr/src/app/secret
volumes:
- name: my-config
configMap:
name: my-config
- name: my-secret
secret:
secretName: my-secret
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: envtest
spec:
replicas: 1
template:
metadata:
labels:
name: envtest
spec:
containers:
- name: envtest
image: gcr.io/<PROJECT_ID>/envtest
ports:
- containerPort: 3000
env:
- name: LANGUAGE
valueFrom:
configMapKeyRef:
name: language
key: LANGUAGE
- name: API_KEY
valueFrom:
secretKeyRef:
name: apikey
key: API_KEY
// Copyright 2017, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License")
var http = require('http');
var server = http.createServer(function (request, response) {
const language = 'English';
const API_KEY = '123-456-789';
response.write(`Language: ${language}\n`);
response.write(`API Key: ${API_KEY}\n`);
response.end(`\n`);
});
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment