diff --git a/group_vars/all.yml b/group_vars/all.yml index 01a824b..b8505fe 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -53,5 +53,8 @@ dns_replicas: 1 # Set to 'false' to disable default Kubernetes UI setup enable_ui: true -# Set fo 'false' to disable default Elasticsearch + Kibana logging setup -enable_logging: true \ No newline at end of file +# Set to 'false' to disable default Elasticsearch + Kibana logging setup +enable_logging: true + +# Set to "false' to disable default Monitoring (cAdvisor + heapster + influxdb + grafana) +enable_monitoring: true diff --git a/roles/addons/files/grafana-service.yaml b/roles/addons/files/grafana-service.yaml new file mode 100644 index 0000000..f1cfb8a --- /dev/null +++ b/roles/addons/files/grafana-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: monitoring-grafana + namespace: kube-system + labels: + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "Grafana" +spec: + ports: + - port: 80 + targetPort: 8080 + selector: + k8s-app: influxGrafana + diff --git a/roles/addons/files/heapster-controller.yaml b/roles/addons/files/heapster-controller.yaml new file mode 100644 index 0000000..fbc3bad --- /dev/null +++ b/roles/addons/files/heapster-controller.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: monitoring-heapster-v8 + namespace: kube-system + labels: + k8s-app: heapster + version: v8 + kubernetes.io/cluster-service: "true" +spec: + replicas: 1 + selector: + k8s-app: heapster + version: v8 + template: + metadata: + labels: + k8s-app: heapster + version: v8 + kubernetes.io/cluster-service: "true" + spec: + containers: + - image: gcr.io/google_containers/heapster:v0.17.0 + name: heapster + resources: + limits: + cpu: 100m + memory: 300Mi + command: + - /heapster + - --source=kubernetes:'' + - --sink=influxdb:http://monitoring-influxdb:8086 diff --git a/roles/addons/files/heapster-service.yaml b/roles/addons/files/heapster-service.yaml new file mode 100644 index 0000000..88c1139 --- /dev/null +++ b/roles/addons/files/heapster-service.yaml @@ -0,0 +1,14 @@ +kind: Service +apiVersion: v1 +metadata: + name: monitoring-heapster + namespace: kube-system + labels: + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "Heapster" +spec: + ports: + - port: 80 + targetPort: 8082 + selector: + k8s-app: heapster diff --git a/roles/addons/files/influxdb-grafana-controller.yaml b/roles/addons/files/influxdb-grafana-controller.yaml new file mode 100644 index 0000000..8a27630 --- /dev/null +++ b/roles/addons/files/influxdb-grafana-controller.yaml @@ -0,0 +1,53 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: monitoring-influx-grafana-v1 + namespace: kube-system + labels: + k8s-app: influxGrafana + version: v1 + kubernetes.io/cluster-service: "true" +spec: + replicas: 1 + selector: + k8s-app: influxGrafana + version: v1 + template: + metadata: + labels: + k8s-app: influxGrafana + version: v1 + kubernetes.io/cluster-service: "true" + spec: + containers: + - image: gcr.io/google_containers/heapster_influxdb:v0.3 + name: influxdb + resources: + limits: + cpu: 100m + memory: 200Mi + ports: + - containerPort: 8083 + hostPort: 8083 + - containerPort: 8086 + hostPort: 8086 + volumeMounts: + - name: influxdb-persistent-storage + mountPath: /data + - image: gcr.io/google_containers/heapster_grafana:v0.7 + name: grafana + resources: + limits: + cpu: 100m + memory: 100Mi + env: + - name: INFLUXDB_EXTERNAL_URL + value: /api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb:api/db/ + - name: INFLUXDB_HOST + value: monitoring-influxdb + - name: INFLUXDB_PORT + value: "8086" + volumes: + - name: influxdb-persistent-storage + emptyDir: {} + diff --git a/roles/addons/files/influxdb-service.yaml b/roles/addons/files/influxdb-service.yaml new file mode 100644 index 0000000..066e052 --- /dev/null +++ b/roles/addons/files/influxdb-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: monitoring-influxdb + namespace: kube-system + labels: + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "InfluxDB" +spec: + ports: + - name: http + port: 8083 + targetPort: 8083 + - name: api + port: 8086 + targetPort: 8086 + selector: + k8s-app: influxGrafana + diff --git a/roles/addons/tasks/main.yml b/roles/addons/tasks/main.yml index 0d4c4b9..99a0348 100644 --- a/roles/addons/tasks/main.yml +++ b/roles/addons/tasks/main.yml @@ -38,4 +38,7 @@ when: enable_ui - include: logging.yml - when: enable_logging \ No newline at end of file + when: enable_logging + +- include: monitoring.yml + when: enable_monitoring diff --git a/roles/addons/tasks/monitoring.yml b/roles/addons/tasks/monitoring.yml new file mode 100644 index 0000000..a9c1a69 --- /dev/null +++ b/roles/addons/tasks/monitoring.yml @@ -0,0 +1,121 @@ +--- +- name: Monitoring | Influxdb | Write controller file + sudo: yes + copy: + src: influxdb-grafana-controller.yaml + dest: "{{ kube_manifest_dir }}/influxdb-grafana-controller.yaml" + register: influxdb_rc_def + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Influxdb | Write service file + sudo: yes + copy: + src: influxdb-service.yaml + dest: "{{ kube_manifest_dir }}/influxdb-service.yaml" + register: influxdb_svc_def + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Grafana | Write service file + sudo: yes + copy: + src: grafana-service.yaml + dest: "{{ kube_manifest_dir }}/grafana-service.yaml" + register: grafana_svc_def + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Heapster | Write controller file + sudo: yes + copy: + src: heapster-controller.yaml + dest: "{{ kube_manifest_dir }}/heapster-controller.yaml" + register: heapster_rc_def + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Heapster | Write service file + sudo: yes + copy: + src: heapster-service.yaml + dest: "{{ kube_manifest_dir }}/heapster-service.yaml" + register: heapster_svc_def + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Influxdb | Create/update replication controller + sudo: yes + kube: + namespace: kube-system + resource: rc + name: monitoring-influx-grafana-v1 + filename: "{{ kube_manifest_dir }}/influxdb-grafana-controller.yaml" + state: "{{ influxdb_rc_def.changed | ternary('latest','present') }}" + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Influxdb | Create/update service + sudo: yes + kube: + namespace: kube-system + resource: svc + name: monitoring-influxdb + filename: "{{ kube_manifest_dir }}/influxdb-service.yaml" + state: "{{ influxdb_svc_def.changed | ternary('latest','present') }}" + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Grafana | Create/update service + sudo: yes + kube: + namespace: kube-system + resource: svc + name: monitoring-grafana + filename: "{{ kube_manifest_dir }}/grafana-service.yaml" + state: "{{ grafana_svc_def.changed | ternary('latest','present') }}" + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Heapster | Create/update replication controller + sudo: yes + kube: + namespace: kube-system + resource: rc + name: monitoring-heapster-v8 + filename: "{{ kube_manifest_dir }}/heapster-controller.yaml" + state: "{{ heapster_rc_def.changed | ternary('latest','present') }}" + when: enable_monitoring + tags: + - addons + - monitoring + +- name: Monitoring | Heapster | Create/update service + sudo: yes + kube: + namespace: kube-system + resource: svc + name: monitoring-heapster + filename: "{{ kube_manifest_dir }}/heapster-service.yaml" + state: "{{ heapster_svc_def.changed | ternary('latest','present') }}" + when: enable_monitoring + tags: + - addons + - monitoring +