k8s配置文件外挂
1.采用hostpath:yaml文件如下apiVersion: v1kind: Servicemetadata:name: zuul-servernamespace: stglabels:app: zuul-serverspec:type: NodePortports:- port: 8088targetPort: 8088nodePort: 32223selector:app: zuul-se
·
1.采用hostpath:yaml文件如下
apiVersion: v1
kind: Service
metadata:
name: zuul-server
namespace: stg
labels:
app: zuul-server
spec:
type: NodePort
ports:
- port: 8088
targetPort: 8088
nodePort: 32223
selector:
app: zuul-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: zuul-server
namespace: stg
labels:
app: zuul-server
spec:
replicas: 1
selector:
matchLabels:
app: zuul-server
template:
metadata:
labels:
app: zuul-server
spec:
containers:
- name: zuul-server
image: 10.10.10.10/zongbu-sre/zuul-server:v202108241
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8088
volumeMounts:
- name: test
mountPath: /var/smart-tg/zuul-server-0.0.1-SNAPSHOT/config/application.yml
volumes:
- name: test
hostPath:
path: /home/dcos/wm/conf/application.yml
type: FileOrCreate
上面配置采用hostpath方式配置外挂文件,这种方式会增加主机与pod的耦合度,非常用方式,再集群中不方便使用,因为这种方式相当于是docker的那种挂载方式,和主机目录是对应的,集群中相当于每台主机上面都要去指定目录下配置文件。
2.采用configmap方式挂载
configMap 卷 提供了向 Pod 注入配置数据的方法。 ConfigMap 对象中存储的数据可以被 configMap 类型的卷引用,然后被 Pod 中运行的 容器化应用使用。
a.创建configmap配置通过文件
kubectl create configmap cmtest --from-file application.yml
b.通过yaml创建configmap
创建configmap.yaml文件
apiVersion: v1
kind: ConfigMap
metadata:
name: cmtest
labels:
app: cmtest
data:
application.yml:
----
server:
port: 8640
servlet:
context-path: /collection
tomcat:
uri-encoding: UTF-8
warnning_email_corn_time: 0 15 08 ? * MON
data_collect_corn_time: 0 40 09 ? * SUN,TUE,WED,THU,FRI,SAT
newcs_email_corn_time: 0 10 18 ? * MON
生成对用configmap
sudo kubectl apply -f configmap.yaml
查看生成的configmap
sudo kubectl describe configmap cmtest
下一步挂载configmap
具体pod collection-pod.yaml文件如下:
apiVersion: v1
kind: Service
metadata:
name: collection
namespace: stg
labels:
app: collection
spec:
type: NodePort
ports:
- port: 8646
targetPort: 8646
nodePort: 32224
selector:
app: collection
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: collection
namespace: stg
labels:
app: collection
spec:
replicas: 1
selector:
matchLabels:
app: collection
template:
metadata:
labels:
app: collection
spec:
containers:
- name: collection
image: 10.10.10.10/zongbu-sre/collection:v20210831
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8646
volumeMounts:
- name: test
mountPath: /var/smart-tg/collection-0.0.1-SNAPSHOT/config/config
volumes:
- name: test
configMap:
name: cmtest
生成pod以及service
sudo kubectl apply -f collection-pod.yaml
更多推荐
已为社区贡献1条内容
所有评论(0)