Skip to content

Instantly share code, notes, and snippets.

@cnych

cnych/Dockerfile

Last active Jun 12, 2019
Embed
What would you like to do?
ConfigMaps and Secrets with Kubernetes
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
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
# -*- 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)
# -*- 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)
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