Skip to content

Instantly share code, notes, and snippets.

@tanan
tanan / deployment.yaml
Created October 9, 2018 04:31
nginx deployment yaml
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))
}

概要

kubernetesのmetricsをPrometheusを利用して収集する

  • 事前準備
  • クラスター構築
  • RBAC設定
  • コンテナ起動
  • namespace設定
  • configmap設定
    • Prometheus
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
@tanan
tanan / role.yaml
Last active March 15, 2018 06:44
k8s ClusterRole setting
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:
@tanan
tanan / web.go
Created February 26, 2018 03:44
prometheus router setting
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)))
@tanan
tanan / main.go
Created February 26, 2018 03:30
reload config file (prometheus.yml)
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)
}
@tanan
tanan / main.go
Last active February 26, 2018 03:28
read arguments in main function.
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: