[k8s]cm挂到不同镜像如何获取env?
要求每个pod挂相同cm模板,得到属于自己的配置具体实现以filebeat镜像为例:docker-entrypoint.sh#!/bin/bashset -execho "pod-ip is $POD_IP"sed -i "s#\#pod-ip#pod-ip: $POD_IP#g" /etc/filebeat/filebeat.yml#注意这句filebeat -e -c /etc/file
·
要求每个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
更多推荐
已为社区贡献21条内容
所有评论(0)