{"id":6238,"date":"2022-08-25T17:53:35","date_gmt":"2022-08-25T08:53:35","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6238"},"modified":"2022-08-25T17:56:00","modified_gmt":"2022-08-25T08:56:00","slug":"autoscaler-job","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6238","title":{"rendered":"Autoscaler job"},"content":{"rendered":"<h1>Autoscaler job<\/h1>\n<h2>Autoscaler job \ub4f1\ub85d<\/h2>\n<pre><code class=\"language-bash\">vi aws_autoscaler.nomad\n-----------------------------\njob &quot;autoscaler&quot; {\n  datacenters = [&quot;dc1&quot;]\n\n  group &quot;autoscaler&quot; {\n    count = 1\n\n    network {\n      port &quot;http&quot; {}\n    }\n\n    task &quot;autoscaler&quot; {\n      driver = &quot;docker&quot;\n      config {\n        image   = &quot;hashicorp\/nomad-autoscaler:0.3.5&quot;\n        ports = [&quot;http&quot;]\n\n        auth_soft_fail = true\n\n        command = &quot;nomad-autoscaler&quot;\n        args = [\n          &quot;agent&quot;,\n          &quot;-config&quot;,\n          &quot;$${NOMAD_TASK_DIR}\/config.hcl&quot;,\n          &quot;-http-bind-address&quot;,\n          &quot;0.0.0.0&quot;,\n          &quot;-http-bind-port&quot;,\n          &quot;$${NOMAD_PORT_http}&quot;,\n          &quot;-policy-dir&quot;,\n          &quot;$${NOMAD_TASK_DIR}\/policies\/&quot;,\n        ]\n      }\n\n      template {\n        data = &lt;&lt;EOF\nnomad {\n  address = &quot;http:\/\/{{env &quot;attr.unique.network.ip-address&quot; }}:4646&quot;\n}\napm &quot;prometheus&quot; {\n  driver = &quot;prometheus&quot;\n  config = {\n    address = &quot;http:\/\/{{ range service &quot;prometheus&quot; }}{{ .Address }}:{{ .Port }}{{ end }}&quot;\n  }\n}\n# Datadog example template is below. In order to use the example config section\n# you will need to remove the first line &quot;#&quot; comments as well as the golang\n# template comment markers which are &quot;- \/*&quot; and &quot;*\/&quot;.\n#\n# apm &quot;datadog&quot; {\n#   driver = &quot;datadog&quot;\n#   config = {\n# {{- \/* with secret &quot;secret\/autoscaler\/datadog&quot; }}\n#     dd_api_key = &quot;{{ .Data.data.api_key }}&quot;\n#     dd_app_key = &quot;{{ .Data.data.app_key }}&quot;\n# {{ end *\/ -}}\n#   }\n# }\ntarget &quot;aws-asg&quot; {\n  driver = &quot;aws-asg&quot;\n  config = {\n    aws_region = &quot;{{ $x := env &quot;attr.platform.aws.placement.availability-zone&quot; }}{{ $length := len $x |subtract 1 }}{{ slice $x 0 $length}}&quot;\n  }\n}\nstrategy &quot;target-value&quot; {\n  driver = &quot;target-value&quot;\n}\nEOF\n\n        destination = &quot;$${NOMAD_TASK_DIR}\/config.hcl&quot;\n      }\n\n      template {\n        data = &lt;&lt;EOF\nscaling &quot;cluster_policy&quot; {\n  enabled = true\n  min     = 1\n  max     = 2\n  policy {\n    cooldown            = &quot;2m&quot;\n    evaluation_interval = &quot;1m&quot;\n    check &quot;cpu_allocated_percentage&quot; {\n      source = &quot;prometheus&quot;\n      query  = &quot;sum(nomad_client_allocated_cpu*100\/(nomad_client_unallocated_cpu+nomad_client_allocated_cpu))\/count(nomad_client_allocated_cpu)&quot;\n      strategy &quot;target-value&quot; {\n        target = 70\n      }\n    }\n    # Datadog example\n    # check &quot;cpu_allocated_percentage&quot; {\n    #   source       = &quot;datadog&quot;\n    #   query        = &quot;avg:nomad.client.allocated.cpu{*}\/(avg:nomad.client.unallocated.cpu{*}+avg:nomad.client.allocated.cpu{*})*100&quot;\n    #   query_window = &quot;2m&quot;\n    #   strategy &quot;target-value&quot; {\n    #     target = 70\n    #   }\n    # }\n    check &quot;mem_allocated_percentage&quot; {\n      source = &quot;prometheus&quot;\n      query  = &quot;sum(nomad_client_allocated_memory*100\/(nomad_client_unallocated_memory+nomad_client_allocated_memory))\/count(nomad_client_allocated_memory)&quot;\n      strategy &quot;target-value&quot; {\n        target = 70\n      }\n    }\n    # Datadog example\n    # check &quot;memory_allocated_percentage&quot; {\n    #   source       = &quot;datadog&quot;\n    #   query        = &quot;avg:nomad.client.allocated.memory{*}\/(avg:nomad.client.unallocated.memory{*}+avg:nomad.client.allocated.memory{*})*100&quot;\n    #   query_window = &quot;2m&quot;\n    #   strategy &quot;target-value&quot; {\n    #     target = 70\n    #   }\n    # }\n    target &quot;aws-asg&quot; {\n      dry-run             = &quot;false&quot;\n      aws_asg_name        = &quot;my-nomad_client&quot;         # client \ub178\ub4dc asg \uc774\ub984\n      node_class          = &quot;hashistack&quot;\n      node_drain_deadline = &quot;5m&quot;\n    }\n  }\n}\nEOF\n\n        destination = &quot;$${NOMAD_TASK_DIR}\/policies\/hashistack.hcl&quot;\n      }\n\n      resources {\n        cpu    = 50\n        memory = 128\n      }\n\n      service {\n        name = &quot;autoscaler&quot;\n        port = &quot;http&quot;\n        check {\n          type     = &quot;http&quot;\n          path     = &quot;\/v1\/health&quot;\n          interval = &quot;5s&quot;\n          timeout  = &quot;2s&quot;\n        }\n      }\n    }\n  }\n}\n-----------------------------<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Autoscaler job Autoscaler job \ub4f1\ub85d vi aws_autoscaler.nomad &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; job &quot;autoscaler&quot; { datacenters = [&quot;dc1&quot;] group &quot;autoscaler&quot; { count = 1 network { port &quot;http&quot; {} } task &quot;autoscaler&quot; { driver = &quot;docker&quot; config { image = &quot;hashicorp\/nomad-autoscaler:0.3.5&quot; ports = [&quot;http&quot;] auth_soft_fail = true command = &quot;nomad-autoscaler&quot; args = [ &quot;agent&quot;, &quot;-config&quot;, &quot;$${NOMAD_TASK_DIR}\/config.hcl&quot;, &quot;-http-bind-address&quot;, &quot;0.0.0.0&quot;, &quot;-http-bind-port&quot;,\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6238\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,30],"tags":[],"class_list":["post-6238","post","type-post","status-publish","format-standard","hentry","category-nomad","category-terraform"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6238"}],"version-history":[{"count":2,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6238\/revisions"}],"predecessor-version":[{"id":6240,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6238\/revisions\/6240"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}