{"id":289069,"date":"2018-09-06T17:55:02","date_gmt":"2018-09-06T13:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=289069"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2018-09-06T13:55:02","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=289069","title":{"rendered":"Kubernetes (k8s) + Helm + GitLab CI\/CD. \u0414\u0435\u043f\u043b\u043e\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/422493\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u0432: \u00abTest\u00bb \u0438 \u00abProduction\u00bb. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0440\u0435\u0434\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0434\u0435\u043f\u043b\u043e\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e HELM. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0438\u0431\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438. \u0412 \u0447\u0435\u043c \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f \u043d\u0438\u0436\u0435. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 runner \u0441 helm-\u043e\u043c \u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0438 \u0443\u043c\u0435\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 HELM-\u043e\u043c.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430: <b>.gitlab-ci.yml<\/b>  <\/p>\n<pre><code>.base_deploy: &amp;base_deploy   stage: deploy   script:   - PROJECT_NAME=\"${CI_PROJECT_NAME}-${CI_ENVIRONMENT_SLUG}\"   - if [[ -z $(helm ls ${PROJECT_NAME} --deployed -q) ]]; then         helm --namespace ${CI_ENVIRONMENT_SLUG} --name ${PROJECT_NAME} install helm --set \"global.env=${CI_ENVIRONMENT_SLUG}\";       else         helm upgrade ${PROJECT_NAME} helm --set \"global.env=${CI_ENVIRONMENT_SLUG}\";       fi  stages:   - deploy  Deploy to Test:   &lt;&lt;: *base_deploy   environment:     name: test  Deploy to Production:   &lt;&lt;: *base_deploy   environment:     name: production   when: manual <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0440\u0435\u0434\u044b \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e: \u00abtest\u00bb \u0438\u043b\u0438 \u00abproduction\u00bb.<br \/>  \u0418\u043c\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u044b \u0442\u043e\u0436\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0438\u043c\u0435\u043d\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b helm \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b (helm ls).<br \/>  \u0414\u0430\u043b\u0435\u0435, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u0441\u0440\u0435\u0434\u0443) \u0432 HELM \u043a\u0430\u043a: \u00abglobal.env\u00bb.<\/p>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 helm \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u0432 \u0432\u0430\u0448\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u044b \u0432 Chat-\u0430\u0445 HELM.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u043e\u0439 <b>values.yaml<\/b>:  <\/p>\n<pre><code>replicas:   test: 1   production: 3  domain:   test: test.domain.com   production: production.domain.com  resources:   requests:     cpu:       _default: 50m       production: 50m     memory:       _default: 256Mi       production: 10Mi   limits:     memory:       _default: 1Gi       production: 1Gi     cpu:       _default: 1000m <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0440\u0435\u0434 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<br \/>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438 default-\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>  \u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f ingress.yaml:<\/p>\n<pre><code>apiVersion: extensions\/v1beta1 kind: Ingress metadata:   name: {{ .Chart.Name }} spec:   rules:   - host: {{ pluck .Values.global.env .Values.domain | first | default .Values.domain._default }}     http:       paths:       - path: \/         backend:           serviceName: {{ .Chart.Name }}           servicePort: 80 <\/code><\/pre>\n<p>  \u0412\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432\u0430\u0448 Chart, \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<pre><code class=\"bash\">helm template .\/helm --set \"global.env=test\" helm template .\/helm --set \"global.env=production\" <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043d\u043e\u0434\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0440\u0435\u0434\u044b.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code>{{ if eq .Values.global.env \"test\" }}       nodeSelector:         nodetype: testnodes {{ else if eq .Values.global.env \"production\" }}       nodeSelector:         nodetype: productionnodes {{ else }} <\/code><\/pre>\n<p>  \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e. \u0414\u0435\u043f\u043b\u043e\u0439\u0442\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e)<\/p><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/422493\/\"> https:\/\/habr.com\/post\/422493\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/422493\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u0432: \u00abTest\u00bb \u0438 \u00abProduction\u00bb. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0440\u0435\u0434\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0434\u0435\u043f\u043b\u043e\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e HELM. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0438\u0431\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438. \u0412 \u0447\u0435\u043c \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f \u043d\u0438\u0436\u0435. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 runner \u0441 helm-\u043e\u043c \u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0438 \u0443\u043c\u0435\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 HELM-\u043e\u043c.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430: <b>.gitlab-ci.yml<\/b>  <\/p>\n<pre><code>.base_deploy: &amp;base_deploy   stage: deploy   script:   - PROJECT_NAME=\"${CI_PROJECT_NAME}-${CI_ENVIRONMENT_SLUG}\"   - if [[ -z $(helm ls ${PROJECT_NAME} --deployed -q) ]]; then         helm --namespace ${CI_ENVIRONMENT_SLUG} --name ${PROJECT_NAME} install helm --set \"global.env=${CI_ENVIRONMENT_SLUG}\";       else         helm upgrade ${PROJECT_NAME} helm --set \"global.env=${CI_ENVIRONMENT_SLUG}\";       fi  stages:   - deploy  Deploy to Test:   &lt;&lt;: *base_deploy   environment:     name: test  Deploy to Production:   &lt;&lt;: *base_deploy   environment:     name: production   when: manual <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0440\u0435\u0434\u044b \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e: \u00abtest\u00bb \u0438\u043b\u0438 \u00abproduction\u00bb.<br \/>  \u0418\u043c\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u044b \u0442\u043e\u0436\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0438\u043c\u0435\u043d\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b helm \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b (helm ls).<br \/>  \u0414\u0430\u043b\u0435\u0435, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u0441\u0440\u0435\u0434\u0443) \u0432 HELM \u043a\u0430\u043a: \u00abglobal.env\u00bb.<\/p>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 helm \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u0432 \u0432\u0430\u0448\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-289069","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=289069"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289069\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=289069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=289069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=289069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}