Last active
September 3, 2021 07:26
-
-
Save cnych/d40756ce6e03035551b6a023135a78d9 to your computer and use it in GitHub Desktop.
ConfigMaps and Secrets with Kubernetes
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
FROM python:3.6.4 | |
# 设置工作目录 | |
RUN mkdir -p /usr/src/app | |
WORKDIR /usr/src/app | |
# 安装依赖 | |
RUN pip install flask | |
# 添加应用 | |
ADD . /usr/src/app | |
# 设置环境变量 | |
ENV TOKEN abcdefg0000 | |
ENV LANGUAGE English | |
# 暴露端口 | |
EXPOSE 5000 | |
# 运行服务 | |
CMD python read-env-app.py |
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: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: envtest | |
labels: | |
name: envtest | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
name: envtest | |
spec: | |
containers: | |
- name: envtest | |
image: cnych/envtest | |
ports: | |
- containerPort: 5000 | |
env: | |
- name: TOKEN | |
valueFrom: | |
secretKeyRef: | |
name: token | |
key: TOKEN | |
- name: LANGUAGE | |
valueFrom: | |
configMapKeyRef: | |
name: language | |
key: LANGUAGE |
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
# -*- coding: utf-8 -*- | |
from flask import Flask, jsonify | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
TOKEN = 'abcdefg123456' | |
LANGUAGE = 'English' | |
return jsonify(token=TOKEN, lang=LANGUAGE) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) |
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
# -*- coding: utf-8 -*- | |
import os | |
from flask import Flask, jsonify | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
TOKEN = os.getenv('TOKEN', '') | |
LANGUAGE = 'English' | |
return jsonify(token=TOKEN, lang=LANGUAGE) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) |
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: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: envtest | |
labels: | |
name: envtest | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
name: envtest | |
spec: | |
containers: | |
- name: envtest | |
image: cnych/envtest | |
ports: | |
- containerPort: 5000 | |
env: | |
- name: TOKEN | |
value: "abcd123456" | |
- name: LANGUAGE | |
value: "English" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment