截取一段错乱的配置:
kubectl -n monitoring get cm blackbox-exporter-configuration -o yaml
apiVersion: v1
data:config.yml: "\"modules\":\n \"http_2xx\":\n \"http\":\n \"preferred_ip_protocol\":\"ip4\"\n \"prober\": \"http\"\n \"http_post_2xx\":\n \"http\":\n \"method\":\"POST\"\n \"preferred_ip_protocol\": \"ip4\"\n \"prober\": \"http\"\n\ \"http_basic_auth_example\":\n \"prober\": http\n \"timeout\" 5s\n \"http\":\n\ \"method\": \"POST\"\n \"preferred_ip_protocol\": \"ip4\"\n \"headers\":\n\ \"Host\": \"127.0.0.1\"\n \"basic_auth\":\n \"username\":\"admin\"\n \"password\": \"Cyc12345\" \n \"irc_banner\":\n \"prober\":\"tcp\"\n \"tcp\":\n \"preferred_ip_protocol\": \"ip4\"\n \"query_response\":\n\ - \"send\": \"NICK prober\"\n - \"send\": \"USER prober prober prober:prober\"\n - \"expect\": \"PING :([^ ]+)\"\n \"send\": \"PONG ${1}\"\n\ - \"expect\": \"^:[^ ]+ 001\"\n \"pop3s_banner\":\n \"prober\": \"tcp\"\n\ \"tcp\":\n \"preferred_ip_protocol\": \"ip4\"\n \"query_response\":\n\ - \"expect\": \"^+OK\"\n \"tls\": true\n \"tls_config\":\n \"insecure_skip_verify\":false\n \"ssh_banner\":\n \"prober\": \"tcp\"\n \"tcp\":\n \"preferred_ip_protocol\":\"ip4\"\n \"query_response\":\n - \"expect\": \"^SSH-2.0-\"\n \"tcp_connect\":\n\ \"prober\": \"tcp\"\n \"tcp\":\n \"preferred_ip_protocol\": \"ip4\"\n\ \"icmp_example\":\n \"prober\": \"icmp\"\n \"timeout\": \"5s\"\n \"icmp\":\n\ \"preferred_ip_protocol\": \"ip4\""
kind: ConfigMap
可能是由于配置文件文件自身存在制表符TAB或者空格,Kubernetes ConfigMap在load过程中发现文件中包含tab缩进,直接转化为\n\t。
# 使用以下方法删除尾随空格
sed -i -E 's/[[:space:]]+$//g' file.txt
# 使用空格替换制表符
sed -i 's/\t/ /g' file.txt
删除原有的重新生成configmap