kubernetesのmetricsをPrometheusを利用して収集する
- 事前準備
- クラスター構築
- RBAC設定
- コンテナ起動
- namespace設定
- configmap設定
- Prometheus
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: nginx-blue | |
namespace: sample-ns | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: nginx |
// ReadMeshConfig gets mesh configuration from a config file | |
func ReadMeshConfig(filename string) (*meshconfig.MeshConfig, error) { | |
yaml, err := ioutil.ReadFile(filename) | |
if err != nil { | |
return nil, multierror.Prefix(err, "cannot read mesh config file") | |
} | |
return model.ApplyMeshConfigDefaults(string(yaml)) | |
} |
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: prometheus | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: prometheus | |
template: |
kind: ClusterRole | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: all-reader | |
rules: | |
- apiGroups: | |
- "" | |
resources: | |
- nodes | |
- nodes/proxy |
global: | |
scrape_interval: 15s | |
evaluation_interval: 15s | |
scrape_configs: | |
- job_name: 'kubernetes-apiservers' | |
kubernetes_sd_configs: | |
- role: endpoints | |
api_server: https://kubernetes.default | |
tls_config: |
router.Get("/", func(w http.ResponseWriter, r *http.Request) { | |
http.Redirect(w, r, path.Join(o.ExternalURL.Path, "/graph"), http.StatusFound) | |
}) | |
router.Get("/alerts", readyf(instrf("alerts", h.alerts))) | |
router.Get("/graph", readyf(instrf("graph", h.graph))) | |
router.Get("/status", readyf(instrf("status", h.status))) | |
router.Get("/flags", readyf(instrf("flags", h.flags))) | |
router.Get("/config", readyf(instrf("config", h.serveConfig))) | |
router.Get("/rules", readyf(instrf("rules", h.rules))) |
func reloadConfig(filename string, logger log.Logger, rls ...func(*config.Config) error) (err error) { | |
level.Info(logger).Log("msg", "Loading configuration file", "filename", filename) | |
defer func() { | |
if err == nil { | |
configSuccess.Set(1) | |
configSuccessTime.SetToCurrentTime() | |
} else { | |
configSuccess.Set(0) | |
} |
a := kingpin.New(filepath.Base(os.Args[0]), "The Prometheus monitoring server") | |
a.Version(version.Print("prometheus")) | |
a.HelpFlag.Short('h') | |
a.Flag("config.file", "Prometheus configuration file path."). | |
Default("prometheus.yml").StringVar(&cfg.configFile) | |
a.Flag("web.listen-address", "Address to listen on for UI, API, and telemetry."). |
spec: | |
containers: | |
- name: fluentd-gcp | |
image: xxxx | |
volumeMounts: | |
- name: config-volume | |
mountPath: /etc/fluent/config.d | |
volumes: | |
- name: config-volume | |
configMap: |