您的位置:首页 > 其它

[k8s]cm挂到不同镜像如何获取env?

2017-09-16 16:53 288 查看

要求每个pod挂相同cm模板,得到属于自己的配置



具体实现

以filebeat镜像为例:

docker-entrypoint.sh

#!/bin/bash

set -ex

echo "pod-ip is $POD_IP"
sed -i "s#\#pod-ip#pod-ip: $POD_IP#g" /etc/filebeat/filebeat.yml  #注意这句
filebeat -e -c /etc/filebeat/filebeat.yml


Dockerfile

FROM docker.elastic.co/beats/filebeat:5.4.1

COPY docker-entrypoint.sh /usr/local/bin/
#RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]


apiVersion: v1
kind: ConfigMap
metadata:
name: tomcat-spring
data:
filebeat.yml: |
filebeat.prospectors:
- input_type: log
fields:
service-name: tomcat-spring
#pod-ip                       # docker-entrypoint.sh会替换这行,具体,先sed获取pod变量值,然后替换这个#pod-ip.
paths:
- "/log/*.txt"
multiline:
pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{3}'
negate: true
match: after
output.elasticsearch:
hosts: ["elasticsearch.logging.svc.cluster.local:9200"]
username: "elastic"
password: "changeme"
template.name: "filebeat"
template.path: "filebeat.template.json"
template.overwrite: true
index: "filebeat-docker-test"
# Available log levels are: critical, error, warning, info, debug
logging.level: info
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: