{"id":8812,"date":"2021-06-06T14:46:30","date_gmt":"2021-06-06T14:46:30","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8812"},"modified":"2021-06-06T14:46:30","modified_gmt":"2021-06-06T14:46:30","slug":"project-tye","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/project-tye\/","title":{"rendered":"Project Tye"},"content":{"rendered":"<p>In the last few posts I&#8217;ve been doing a lot of stuff with ASP.NET core services and clients within Kubernetes and whilst you&#8217;ve seen it&#8217;s not too hard to create a docker container\/image out of services and clients, deploy to the local registry and then deploy using Kubernetes scripts, after a while you&#8217;re likely to find this tedious and want to wrap everything into a shell\/batch script &#8211; an alternative is to use <a href=\"https:\/\/github.com\/dotnet\/tye\" rel=\"noopener\" target=\"_blank\">Project Tye<\/a>.<\/p>\n<p><strong>What is Project Tye?<\/strong><\/p>\n<p>I recommend checking out <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/dotnet\/tye\" rel=\"noopener\" target=\"_blank\">Project Tye<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/aspnet\/introducing-project-tye\/\" rel=\"noopener\" target=\"_blank\">Introducing Project Tye<\/a><\/li>\n<li><a href=\"https:\/\/channel9.msdn.com\/Shows\/On-NET\/Building-microservices-with-Tye\" rel=\"noopener\" target=\"_blank\">Building microservices with Tye<\/a><\/li>\n<\/ul>\n<p>The basics are Project Tye can be used to take .NET projects, turn them into docker images and generate the deployments to k8s with a single command. Also Project Tye allows us to undeploy with a single command also .<\/p>\n<p><strong>Installing Project Tye<\/strong><\/p>\n<p>I&#8217;m using a remote Ubuntu server to run my Kubernetes cluster, so we&#8217;ll need to ensure that .NET 3.1 SDK is installed (hopefully Tye will work with 5.0 in the near future but for the current release I needed .NET 3.1.x installed.<\/p>\n<p>To check your current list of SDK&#8217;s run<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndotnet --list-sdks\r\n<\/pre>\n<p>Next up you need to run the dotnet tool to install Tye, using<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndotnet tool install -g Microsoft.Tye --version &quot;0.7.0-alpha.21279.2&quot;\r\n<\/pre>\n<p><em>Obviously change the version to whatever the latest build is &#8211; that was the latest available as of 6th June 2021.<\/em><\/p>\n<p>The tool will be deployed to<\/p>\n<ul>\n<li>Linux &#8211; $HOME\/.dotnet\/tools<\/li>\n<li>Windows &#8211; %USERPROFILE%\\.dotnet\\tools<\/li>\n<\/ul>\n<p><strong>Running Project Tye<\/strong><\/p>\n<p>It&#8217;s as simple as running the following command in your solution folder<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntye deploy --interactive\r\n<\/pre>\n<p>This is the interactive version and you&#8217;ll be prompted to supply the registry you wish to push your docker images to, as we&#8217;re using localhost:32000, remember to set that as your registry, or better still we can create a tye.yaml file with configuration for Project Tye within the solution folder, here&#8217;s an example<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nname: myapp\r\nregistry: localhost:32000\r\nservices:\r\n- name: frontend\r\n  project: frontend\/razordemo.csproj\r\n- name: backend\r\n  project: backend\/weatherservice.csproj\r\n<\/pre>\n<p>Now with this in place we can just run<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntye deploy\r\n<\/pre>\n<p>If you want to create a default tye.yaml file then run <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntye init\r\n<\/pre>\n<p>Project Tye will now build our docker images, push to localhost:3200 and then generate deployments, services etc. within Kubernetes based upon the configuration. Check out the JSON schema for the Tye configuration file <a href=\"https:\/\/github.com\/dotnet\/tye\/blob\/main\/src\/schema\/tye-schema.json\" rel=\"noopener\" target=\"_blank\">tye-schema.json<\/a> for all the current options.<\/p>\n<p>Now you&#8217;ve deployed everything and it&#8217;s up and running, but Tye also includes environment configurations, for example<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nenv:\r\n  - name: DOTNET_LOGGING__CONSOLE__DISABLECOLORS\r\n    value: 'true'\r\n  - name: ASPNETCORE_URLS\r\n    value: 'http:\/\/*'\r\n  - name: PORT\r\n    value: '80'\r\n  - name: SERVICE__RAZORDEMO__PROTOCOL\r\n    value: http\r\n  - name: SERVICE__RAZORDEMO__PORT\r\n    value: '80'\r\n  - name: SERVICE__RAZORDEMO__HOST\r\n    value: razordemo\r\n  - name: SERVICE__WEATHERSERVICE__PROTOCOL\r\n    value: http\r\n  - name: SERVICE__WEATHERSERVICE__PORT\r\n    value: '80'\r\n  - name: SERVICE__WEATHERSERVICE__HOST\r\n    value: weatherservice\r\n<\/pre>\n<p>Just add the following NuGet package to your project(s)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;PackageReference Include=&quot;Microsoft.Tye.Extensions.Configuration&quot; Version=&quot;0.2.0-*&quot; \/&gt;\r\n<\/pre>\n<p>and then you can interact with the configuration using the TyeConfigurationExtensions classes from that package. For example using the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nclient.BaseAddress = Configuration.GetServiceUri(&quot;weatherservice&quot;);\r\n<\/pre>\n<p><strong>Ingress<\/strong><\/p>\n<p>You can also include ingress configuration within your tye.yaml, for example<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ningress: \r\n  - name: ingress  \r\n    # bindings:\r\n    #   - port: 8080\r\n    rules:\r\n      - path: \/\r\n        service: razordemo\r\n<\/pre>\n<p>however, as an Ingress might be shared across services\/applications this will not be undeployed using the <em>undeploy<\/em> command, so not to affect potentially other applications, you can force it to be undeployed using<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nkubectl delete -f https:\/\/aka.ms\/tye\/ingress\/deploy\r\n<\/pre>\n<p>See <a href=\"https:\/\/github.com\/dotnet\/tye\/blob\/main\/docs\/recipes\/ingress.md\" rel=\"noopener\" target=\"_blank\">Ingress<\/a> for more information on Tye and Ingress.<\/p>\n<p><strong>Dependencies<\/strong><\/p>\n<p>Along with our solution\/projects we can also deploy dependencies as part of the deployment, for example if we need to also deploy a redis cache, dapr or other images. Just add the dependency to the tye.yaml like this<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n- name: redis\r\n  image: redis\r\n  bindings:\r\n    - port: 6379\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In the last few posts I&#8217;ve been doing a lot of stuff with ASP.NET core services and clients within Kubernetes and whilst you&#8217;ve seen it&#8217;s not too hard to create a docker container\/image out of services and clients, deploy to the local registry and then deploy using Kubernetes scripts, after a while you&#8217;re likely to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[200,314,315],"tags":[],"class_list":["post-8812","post","type-post","status-publish","format-standard","hentry","category-asp-net-core","category-kubernetes","category-tye"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8812"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8812\/revisions"}],"predecessor-version":[{"id":8822,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8812\/revisions\/8822"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}