通過Http API的方式更改k8s中的configmap
1、在PUT
中直接輸入json串會因為格式原因報出各種各樣的錯誤,因此
將修改後的configmap存到configmap_core.json
檔案中。
curl -X PUT -u k8s_usrname:k8s _password -H 'Content-Type: application/json' --data-binary @configmap_core.json https://10.4.**.**:6443/api/v1/namespaces/monitoring/configmaps/prometheus-rules
API參考:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#replace-195
PUT理解:https://blog.csdn.net/weixin_38070561/article/details/83272480
注1:這裡必須加-u
引數指定k8s的使用者名稱和密碼,否則連線會被拒絕。
注2:-H "Content-Type:application/json"
表示使用JSON形式post資料。
注3:-X
指定請求方式是GET還是POST。
GET 方法相對簡單,只要把資料附在網址後面就行。
curl example.com/form.cgi?data=xxx
POST 方法則必須把資料和網址分開,curl 就要用到 --data 或者 -d 引數。-d
後面的是post的資料。
curl -X POST --data "data=xxx" example.com/form.cgi
curl -X POST -d"data=123&key=456" http://localhost:8080/search
2、prometheus熱載入
curl -X POST http://10.4.**.**:31391/-/reload
注1:二進位制檔案啟動時,如果要熱載入prometheus,埠為9090。如果要熱載入altermanager,則需要將埠改成9093。
注2:直接執行會提示API不可用。需要修改prometheus的Dockerfile檔案,重新打映象。預設的peometheus是以nobody使用者啟動,需要增加--web.enable-lifecycle
注3:在熱載入的過程中,如果Prometheus監控的是k8s叢集,那麼需要在prometheus被分配的到的那個Node節點上執行熱載入指令,才可以生效。在主節點執行不生效。
Dockerfile檔案修改為:
FROM quay.io/prometheus/busybox:latest
LABEL maintainer "保持不變"
COPY prometheus /bin/prometheus
COPY promtool /bin/promtool
COPY prometheus.yml /etc/prometheus/prometheus.yml
COPY console_libraries/ /usr/share/prometheus/console_libraries/
COPY consoles/ /usr/share/prometheus/consoles/
RUN ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/
RUN mkdir -p /prometheus
EXPOSE 9090
VOLUME [ "/prometheus" ]
WORKDIR /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD [ "--config.file=/etc/prometheus/prometheus.yml", \
"--storage.tsdb.path=/prometheus", \
"--web.console.libraries=/usr/share/prometheus/console_libraries", \
"--web.enable-lifecycle", \
"--web.console.templates=/usr/share/prometheus/consoles" ]
接著執行(不要遺漏最後的點):docker build -t prom/prometheus:v.0.0.0 .
在起版本號是不要起latest,可能會造成拉取失敗。
將映象拷貝到目標節點,docker load < *.tar
。
接著修改deployment.yaml
,修改內容有兩方面。一方面是修改image:
映象的名字。一方面是在args:
加上--web.enable-lifecycle
引數。
最後執行ps -ef | grep prometheus
檢視更改是否生效,成功的標誌為
prometheus --config.file /etc/prometheus/prometheus.yml --web.enable-lifecycl
參考:
https://blog.csdn.net/chenleiking/article/details/80182086