{"id":12637,"date":"2017-10-31T11:07:16","date_gmt":"2017-10-31T11:07:16","guid":{"rendered":"https:\/\/blog.jetbrains.com\/teamcity\/?p=6281"},"modified":"2017-11-20T12:38:52","modified_gmt":"2017-11-20T12:38:52","slug":"teamcity-kubernetes-support-plugin","status":"publish","type":"teamcity","link":"https:\/\/blog.jetbrains.com\/fr\/teamcity\/2017\/10\/teamcity-kubernetes-support-plugin","title":{"rendered":"TeamCity Kubernetes Support Plugin"},"content":{"rendered":"<p>Kubernetes nowadays is quite a popular way to run Docker containers. A number of teams and organizations already have a Kubernetes cluster configured and used in production.<\/p>\n<p>Now with the help of the TeamCity Kubernetes Support plugin, it is possible to use the same infrastructure to run TeamCity build agents.<\/p>\n<p>The plugin is compatible with TeamCity 2017.1.x and later.<\/p>\n<p>First, <a href=\"https:\/\/plugins.jetbrains.com\/plugin\/9818-kubernetes-cloud-support\" target=\"_blank\" rel=\"noopener\">download<\/a> the plugin and install it on the TeamCity server <a href=\"https:\/\/confluence.jetbrains.com\/display\/TCD10\/Installing+Additional+Plugins\" target=\"_blank\" rel=\"noopener\">as usual<\/a>.<\/p>\n<p>Then you can start by <a href=\"https:\/\/confluence.jetbrains.com\/display\/TCD10\/Agent+Cloud+Profile\" target=\"_blank\" rel=\"noopener\">configuring a cloud profile<\/a> in a project:<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-1-new.png\" rel=\"attachment wp-att-6300\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6300\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-1-new.png\" alt=\"kub-1-new\" width=\"600\" \/><\/a><\/p>\n<p>Specify the URL of the Kubernetes API server (aka Kubernetes master), select the appropriate namespace.<\/p>\n<p>Select one of the Kubernetes API authentication options:<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-2.png\" rel=\"attachment wp-att-6284\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6284\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-2.png\" alt=\"kub-2\" width=\"600\" \/><\/a><\/p>\n<p>The next step after connecting to the Kubernetes API is creating a cloud image.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-3.png\" rel=\"attachment wp-att-6285\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6285\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-3.png\" alt=\"kub-3\" width=\"600\" \/><\/a><\/p>\n<p>There are two options available:<\/p>\n<ul>\n<li><strong>Simply run single container<\/strong>: good choice for those who don\u2019t know about all the powerful Kubernetes features but want to simply run its container;<\/li>\n<li><strong>Use pod template from deployment<\/strong>: will handle all the possible advanced scenarios of configuring workload to a Kubernetes cluster like <em>multi-container pods, node\/pod affinity and toleration<\/em>, etc.<\/li>\n<\/ul>\n<p>When the \u201cSimply run single container\u201d mode is selected, users can specify the name of the Docker image with the build agent they want to use.<\/p>\n<p>In our setup, we are using the <a href=\"https:\/\/hub.docker.com\/r\/jetbrains\/teamcity-agent\/\" target=\"_blank\" rel=\"noopener\">official TeamCity Build Agent image<\/a> which is supported by the plugin. You can also create your own image.<\/p>\n<p>Other options like Docker command, Docker arguments, and image pull policy, will be useful as well.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-4.png\" rel=\"attachment wp-att-6286\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6286\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-4.png\" alt=\"kub-4\" width=\"600\" \/><\/a><\/p>\n<p>Another cloud image option is \u2018Use pod template from deployment\u2019.<\/p>\n<p>Here you simply specify a deployment name: remember to check that the deployment belongs to the same namespace you\u2019ve provided in the cloud profile. You can either use the <a href=\"https:\/\/hub.docker.com\/r\/jetbrains\/teamcity-agent\/\" target=\"_blank\" rel=\"noopener\">official TeamCity Build Agent image<\/a> in your deployment like in the example below, or your own image.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-5.png\" rel=\"attachment wp-att-6287\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6287\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-5.png\" alt=\"kub-5\" width=\"600\" \/><\/a><\/p>\n<p>There is a small trick here. When given a deployment name, the plugin will not actually use it as deployment, but it will extract the <a href=\"https:\/\/kubernetes.io\/docs\/resources-reference\/v1.7\/#podtemplatespec-v1-core\" target=\"_blank\" rel=\"noopener\">PodTemplateSpec<\/a> section from its definition and use it to create the plugin\u2019s own pods. The plugin\u2019s own pods means that the pods will not be connected to deployment anyhow. The Kubernetes deployments feature will not be used to manage the pods\u2019 lifecycle. The TeamCity server will take care of those pods on its own. Deployment will be used as a container of <a href=\"https:\/\/kubernetes.io\/docs\/api-reference\/v1.7\/#podtemplatespec-v1-core\" target=\"_blank\" rel=\"noopener\">PodTemplateSpec<\/a> which can be referenced by name.<\/p>\n<p>After a cloud profile is created and saved, you will be able to start TeamCity agents running in containers in the scope of the pods on the Kubernetes cluster. TeamCity will mark every started pod with a set of specific labels.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-6.png\" rel=\"attachment wp-att-6288\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-6288\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/10\/teamcity-kub-6.png\" alt=\"kub-6\" width=\"554\" height=\"173\" \/><\/a><\/p>\n<p>Using those labeled pods, you can always determine which TeamCity server started a particular pod, which cloud profile and cloud image are affected.<\/p>\n<p>Feel free to <a href=\"https:\/\/plugins.jetbrains.com\/plugin\/9818-kubernetes-cloud-support\" target=\"_blank\" rel=\"noopener\">download<\/a> the plugin, <a href=\"https:\/\/confluence.jetbrains.com\/display\/TCDL\/Installing+Additional+Plugins\" target=\"_blank\" rel=\"noopener\">try it<\/a>, and <a href=\"https:\/\/github.com\/JetBrains\/teamcity-kubernetes-plugin\/issues\" target=\"_blank\" rel=\"noopener\">share your feedback<\/a> with us!<\/p>\n<p>Or you can <a href=\"https:\/\/teamcity.jetbrains.com\/invitations.html?token=cVgEakjOhVHDYOjCm2SCDAX7G2tUZc73\" target=\"_blank\" rel=\"noopener\">TestDrive<\/a> it in the cloud.<\/p>\n<p>Happy building with TeamCity!<\/p>\n","protected":false},"author":313,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[808,11,1401],"tags":[],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/teamcity\/12637"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/teamcity"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/types\/teamcity"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/users\/313"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/comments?post=12637"}],"version-history":[{"count":0,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/teamcity\/12637\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media?parent=12637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/categories?post=12637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/tags?post=12637"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/cross-post-tag?post=12637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}