Permalink
Browse files

tidying up

fixed flake8 complaints
made node template naming consistent
added scale up/down and healing
made etcd and flannel inputs
  • Loading branch information...
1 parent 32b008a commit 7e31dd1d5be795302f814de5d04c91b39e5823fe earthmant committed Jun 21, 2016
@@ -8,6 +8,7 @@ imports:
- http://getcloudify.org/spec/cloudify/3.3.1/types.yaml
- http://getcloudify.org/spec/diamond-plugin/1.3.1/plugin.yaml
- http://getcloudify.org/spec/openstack-plugin/1.3.1/plugin.yaml
+ - types/scale.yaml
inputs:
@@ -28,9 +29,24 @@ inputs:
The port that the master API will respond to.
default: 8080
+ etcd_version:
+ description: >
+ The etcd version.
+ default: '2.0.12'
+
+ flannel_version:
+ description: >
+ The flannel version
+ default: '0.5.3'
+
+ kubernetes_version:
+ description: >
+ The kubernetes version.
+ default: 'v1.0.1'
+
node_templates:
- master_host:
+ kubernetes_master_host:
type: cloudify.openstack.nodes.Server
instances:
deploy: 1
@@ -50,19 +66,19 @@ node_templates:
sudo service docker restart
sudo service ssh start
relationships:
- - target: master_security_group
+ - target: kubernetes_security_group
type: cloudify.openstack.server_connected_to_security_group
- type: cloudify.openstack.server_connected_to_floating_ip
- target: master_ip
+ target: kubernetes_master_ip
- master_ip:
+ kubernetes_master_ip:
type: cloudify.openstack.nodes.FloatingIP
- master_security_group:
+ kubernetes_security_group:
type: cloudify.openstack.nodes.SecurityGroup
properties:
security_group:
- name: master_security_group
+ name: kubernetes_security_group
description: kubernetes master security group
rules:
- remote_ip_prefix: 0.0.0.0/0 # for remote install
@@ -74,40 +90,44 @@ node_templates:
- remote_ip_prefix: 0.0.0.0/0 # for service
port: 30000
- docker_master:
+ docker_kubernetes_master:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
start: scripts/docker/bootstrap.py
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- etcd:
+ etcd_kubernetes_master:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/etcd/create.py
+ inputs:
+ etcd_version: { get_input: etcd_version }
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- type: cloudify.relationships.depends_on
- target: docker_master
+ target: docker_kubernetes_master
- flannel:
+ flannel_kubernetes_master:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/flannel/master/create.py
+ inputs:
+ flannel_version: { get_input: flannel_version }
configure:
implementation: scripts/flannel/master/configure.py
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- type: cloudify.relationships.depends_on
- target: etcd
+ target: etcd_kubernetes_master
kubernetes_master:
type: cloudify.nodes.Root
@@ -123,11 +143,11 @@ node_templates:
master_port: { get_input: master_port }
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- type: cloudify.relationships.depends_on
- target: flannel
+ target: flannel_kubernetes_master
- kubernetes_proxy:
+ kubernetes_master_proxy:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
@@ -137,7 +157,7 @@ node_templates:
master_port: { get_input: master_port }
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- type: cloudify.relationships.depends_on
target: kubernetes_master
@@ -149,9 +169,9 @@ node_templates:
implementation: scripts/kubernetes/kubectl.py
relationships:
- type: cloudify.relationships.contained_in
- target: master_host
+ target: kubernetes_master_host
- type: cloudify.relationships.depends_on
- target: kubernetes_proxy
+ target: kubernetes_master_proxy
kubernetes_node_host:
type: cloudify.openstack.nodes.Server
@@ -173,10 +193,55 @@ node_templates:
service docker stop
service ssh start
relationships:
- - target: master_security_group
+ - target: kubernetes_security_group
type: cloudify.openstack.server_connected_to_security_group
+ interfaces:
- docker_node:
+ ###########################################################
+ # We are infact telling cloudify to install a diamond
+ # monitoring agent on the server.
+ #
+ # (see https://github.com/BrightcoveOS/Diamond)
+ ###########################################################
+
+ cloudify.interfaces.monitoring_agent:
+ install:
+ implementation: diamond.diamond_agent.tasks.install
+ inputs:
+ diamond_config:
+ interval: 1
+ start: diamond.diamond_agent.tasks.start
+ stop: diamond.diamond_agent.tasks.stop
+ uninstall: diamond.diamond_agent.tasks.uninstall
+
+ ###########################################################
+ # Adding some collectors. These collectors are necessary
+ # for the Cloudify UI to display the deafult metrics.
+ ###########################################################
+
+ cloudify.interfaces.monitoring:
+ start:
+ implementation: diamond.diamond_agent.tasks.add_collectors
+ inputs:
+ collectors_config:
+ CPUCollector: {}
+ MemoryCollector: {}
+ LoadAverageCollector: {}
+ DiskUsageCollector:
+ config:
+ devices: x?vd[a-z]+[0-9]*$
+ NetworkCollector: {}
+ ProcessResourcesCollector:
+ config:
+ enabled: true
+ unit: B
+ measure_collector_time: true
+ cpu_interval: 0.5
+ process:
+ hyperkube:
+ name: hyperkube
+
+ docker_kubernetes_node:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
@@ -185,21 +250,22 @@ node_templates:
- type: cloudify.relationships.contained_in
target: kubernetes_node_host
- flannel_node:
+ flannel_kubernetes_node:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/flannel/node/create.py
inputs:
- master_ip: { get_attribute: [ master_host, ip ] }
+ master_ip: { get_attribute: [ kubernetes_master_host, ip ] }
+ flannel_version: { get_input: flannel_version }
relationships:
- type: cloudify.relationships.contained_in
target: kubernetes_node_host
- type: cloudify.relationships.depends_on
- target: docker_node
+ target: docker_kubernetes_node
- type: cloudify.relationships.connected_to
- target: kubernetes_proxy
+ target: kubernetes_master_proxy
kubernetes_node:
type: cloudify.nodes.Root
@@ -208,35 +274,100 @@ node_templates:
start:
implementation: scripts/kubernetes/node/start.py
inputs:
- master_ip: { get_attribute: [ master_host, ip ] }
+ master_ip: { get_attribute: [ kubernetes_master_host, ip ] }
master_port: { get_input: master_port }
relationships:
- type: cloudify.relationships.connected_to
target: kubernetes_master
- type: cloudify.relationships.contained_in
target: kubernetes_node_host
- type: cloudify.relationships.depends_on
- target: flannel_node
+ target: flannel_kubernetes_node
- type: cloudify.relationships.depends_on
- target: kubernetes_proxy
+ target: kubernetes_master_proxy
- kubernetes_proxy_node:
+ kubernetes_node_proxy:
type: cloudify.nodes.Root
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: scripts/kubernetes/node/proxy.py
inputs:
- master_ip: { get_attribute: [ master_host, ip ] }
+ master_ip: { get_attribute: [ kubernetes_master_host, ip ] }
master_port: { get_input: master_port }
relationships:
- type: cloudify.relationships.contained_in
target: kubernetes_node_host
- type: cloudify.relationships.depends_on
target: kubernetes_node
+groups:
+
+ scale_up_group:
+ members: [kubernetes_node_host]
+ policies:
+ auto_scale_up:
+ type: scale_policy_type
+ properties:
+ policy_operates_on_group: true
+ scale_limit: 6
+ scale_direction: '<'
+ scale_threshold: 3
+ service_selector: .*kubernetes_node_host.*.process.hyperkube.cpu.percent
+ cooldown_time: 60
+ triggers:
+ execute_scale_workflow:
+ type: cloudify.policies.triggers.execute_workflow
+ parameters:
+ workflow: scale
+ workflow_parameters:
+ delta: 1
+ node_id: kubernetes_node_proxy
+ scale_compute: true
+
+ scale_down_group:
+ members: [kubernetes_node_host]
+ policies:
+ auto_scale_down:
+ type: scale_policy_type
+ properties:
+ scale_limit: 2
+ scale_direction: '>'
+ scale_threshold: 1
+ service_selector: .*kubernetes_node_host.*.process.hyperkube.cpu.percent
+ cooldown_time: 60
+ moving_window_size: 200
+ triggers:
+ execute_scale_workflow:
+ type: cloudify.policies.triggers.execute_workflow
+ parameters:
+ workflow: scale
+ workflow_parameters:
+ delta: -1
+ node_id: kubernetes_node_proxy
+ scale_compute: true
+
+ heal_group:
+ members: [kubernetes_node_host]
+ policies:
+ simple_autoheal_policy:
+ type: cloudify.policies.types.host_failure
+ properties:
+ service:
+ - .*kubernetes_node_host.*.cpu.total.system
+ - .*kubernetes_node_host.*.process.hyperkube.cpu.percent
+ interval_between_workflows: 60
+ triggers:
+ auto_heal_trigger:
+ type: cloudify.policies.triggers.execute_workflow
+ parameters:
+ workflow: heal
+ workflow_parameters:
+ node_instance_id: { 'get_property': [ SELF, node_id ] }
+ diagnose_value: { 'get_property': [ SELF, diagnose ] }
+
outputs:
kubernetes_info:
description: Kuberenetes master info
value:
- url: {concat: ["http://",{ get_attribute: [ master_ip, floating_ip_address ]},":", { get_input: master_port } ] }
+ url: {concat: ["http://",{ get_attribute: [ kubernetes_master_ip, floating_ip_address ]},":", { get_input: master_port } ] }
View
@@ -0,0 +1,49 @@
+(where (service #"{{service_selector}}")
+ #(info "got event: " %)
+
+ (where (not (expired? event))
+ (moving-time-window {{moving_window_size}}
+ (fn [events]
+ (let [
+ hostmap (atom {})
+ hostcnt (atom {})
+ ]
+ (do
+ (doseq [m events]
+ (if (nil? (@hostmap (m :host)))
+ (do
+ (swap! hostmap assoc (m :host) (m :metric))
+ (swap! hostcnt assoc (m :host) 1)
+ )
+ (do
+ (swap! hostmap assoc (m :host) (+ (m :metric) (@hostmap (m :host))))
+ (swap! hostcnt assoc (m :host) (inc (@hostcnt (m :host))))
+ )
+ )
+ )
+ (doseq [entry @hostmap]
+ (swap! hostmap assoc (key entry) (/ (val entry) (@hostcnt (key entry))))
+ )
+
+ (let
+ [ hostcnt (count @hostmap)
+ conns (/ (apply + (map (fn [a] (val a)) @hostmap)) hostcnt)
+ cooling (not (nil? (riemann.index/lookup index "scaling" "suspended")))]
+
+ (do
+ (info "cooling=" cooling " scale_direction={{scale_direction}} hostcnt=" hostcnt " scale_threshold={{scale_threshold}} conns=" conns)
+ (if (and (not cooling) ({{scale_direction}} hostcnt {{scale_limit}}) ({{scale_direction}} {{scale_threshold}} conns))
+ (do
+ (info "=== SCALE ===" "{{scale_direction}}")
+ (process-policy-triggers {})
+ (riemann.index/update index {:host "scaling" :service "suspended" :time (unix-time) :description "cooldown flag" :metric 0 :ttl {{cooldown_time}} :state "ok"})
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+)
Oops, something went wrong.

0 comments on commit 7e31dd1

Please sign in to comment.