Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the installation and usage of Tye in K8s

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about the installation and usage of Tye in K8s, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Recently, we happen to be developing a new version of Newbe.Claptrap, in which Tye is used to assist the development of k8s applications.

Install Tye

First, make sure that dotnet SDK of netcore 2.1 or above is installed correctly.

Tye is currently under development, so you can only install the preview version for use at this time. Use the link below to search for the latest version and copy the CLI installation on the interface.

Https://www.nuget.org/packages/Microsoft.Tye/

Dotnet tool install-global Microsoft.Tye-version 0.6.0-alpha.21070.5

After the installation is complete, run tye in the console and you can view the following results:

PS C:\ tools\ Cmder > tyetye: Developer tools and publishing for microservices.Usage: tye [options] [command] Options:-- no-default Disable default options from environment variables -?,-h -- help Show help and usage information-- version Show version informationCommands: init create a yaml manifest run run the application build build containers for the application push build and push application containers to registry deploy deploy the application undeploy delete deployed application creates and runs a test project

Next let's create a netcore application to test the deployment scenario. Select an appropriate location and run the following command to create the test project:

Dotnet new sln-n TyeTestdotnet new webapi-n TyeTestdotnet sln.\ TyeTest.sln add.\ TyeTest\ TyeTest.csproj

In this way, we have a test solution and a WebApi project. We can run the following command to start the service locally:

Dotnet run-project.\ TyeTest\ TyeTest.csproj

After startup, you can open https://localhost:5001/swagger/index.html in a browser to view the launched swagger interface.

Use tye to run applications locally

Next, we close the previous running application and start the test application locally using tye instead.

Under the solution directory, use the console to run the following command:

Tye run

After running, you may get the following results:

PS C:\ Repos\ TyeTest > tye runLoading Application Details...Launching Tye Host... [12:11:30 INF] Executing application from C:\ Repos\ TyeTest\ TyeTest.sln [12: 11:30 INF] Dashboard running on http://127.0.0.1:8000[12:11:30 INF] Building projects [12:11:32 INF] Launching service tyetest_9dd91ae4-f: C:\ Repos\ TyeTest\ TyeTest\ bin\ Debug\ net5.0\ TyeTest.exe [12: 11:32 INF] tyetest _ 9dd91ae4-f running on process id 24552 bound to http://localhost:14099, Https://localhost:14100[12:11:32 INF] Replica tyetest_9dd91ae4-f is moving to a ready state [12:11:32 INF] Selected process 24552. [12:11:33 INF] Listening for event pipe events for tyetest_9dd91ae4-f on process id 24552

Follow the prompts above to successfully launch the tye dashboard in http://127.0.0.1:8000. Open dashboard using a browser to see a list of applications that have been deployed. As shown in the following figure:

Through dashboard, you can see that the test program has been started and bound with http://localhost:14099 and https://localhost:14100. In fact, in self-testing, the two ports are randomly selected, so they will be different.

When we open swagger through the https binding exposed above, we can see the same effect as using dotnet run before: https://localhost:14100/swagger

Deploy a k8s locally

Next, we will deploy the application to K8s using Tye. So in order to achieve this effect, you first need to prepare a k8s.

There are many ways to deploy k8s on the development machine, this experiment uses the scheme of Docker Desktop + K8s, the reason is nothing else, or because there are more or less problems in the process of using other schemes. Specific developers can make their own choices.

The solution of Docker Desktop + K8s is described clearly in the following link. It is recommended that developers refer to:

"Docker Desktop starts Kubernetes" https://www.cnblogs.com/weschen/p/12658839.html

In this experiment, in addition to K8s ontology, you also need to install nginx ingress and helm. You can also refer to the above article for installation.

Deploy the application to k8s

But after K8s is configured, we can use tye to quickly publish the application to K8s for viewing.

Log in to docker registry

First, you need to configure docker registry for the local docker. Because during publishing using tye, the packaged docker image of the project will be pushed to a docker registry.

Developers can choose a variety of ways to get their own docker registry:

Nexus OSS Repository

Aliyun, Tencent Cloud, DaoCloud and so on all have docker registry with free quota.

Docker hub, if the network is all right

Use docker login to log in to your docker registry.

Tye init creates tye.yml

In the solution directory, run the following command to create the tye.yml configuration file:

Tye init

After running, you will get the following files in the solution folder:

Name: tyetestservices:-name: tyetest project: TyeTest/TyeTest.csproj

This is the simplest tye.yml file.

Modify tye.yml

We add a line to tye.yml about the configuration of docker registry to specify where the constructed image will be pushed:

Name: tyetestregistry: registry.cn-hangzhou.aliyuncs.com/newbe36524services:-name: tyetest project: TyeTest/TyeTest.csproj

For example, the author uses the docker registry of Aliyun Hangzhou node and the namespace is newbe36524. So a line registry: registry.cn-hangzhou.aliyuncs.com/newbe36524 is added.

This is equivalent to, if you build, an image with a tag of registry.cn-hangzhou.aliyuncs.com/newbe36524/tyetest:1.0.0 will be built and pushed to the Ali cloud.

Download netcore basic image in advance

Because this time we are releasing netcore programs, they will be built netcore images, therefore, in order to build more smoothly, it is recommended to use the acceleration tool to download the basic image locally in advance.

For example, the author uses the net5 TFM application in this use, so you need to pull the mcr.microsoft.com/dotnet/aspnet:5.0 locally as the basic image.

Because the source of the netcore basic image has now been migrated from docker hub to mcr.microsoft.com. Therefore, it is recommended to use Newbe.McrMirror to accelerate downloads.

For more information on how to use it, please see https://github.com/newbe36524/Newbe.McrMirror

If developers do not know what the basic image they need to pull is, they can also try the following step to publish directly, check the basic image content used in the process, and then pull it.

Use tye deploy

Now that everything is in place, continue to run the following command in the solution directory to publish:

Tye deploy

You may get the following results:

PS C:\ Repos\ TyeTest > tye deployLoading Application Details...Verifying kubectl installation...Verifying kubectl connection to cluster...Processing Service 'tyetest'... Applying container defaults... Compiling Services... Publishing Project... Building Docker Image... # 1 [internal] load build definition from Dockerfile # 1 sha256:a3872c76e0ccfd4bade43ecac3349907e0d110092c3ca8c61f1d360689bad7e2 # 1 transferring dockerfile: 144B done # 1 DONE 0.0s # 2 [internal] load .do ckerignore # 2 sha256:9e3b70115b86134ab4be5a3ce629a55cd6060936130c89b906677d1958215910 # 2 transferring context: 2B done # 2 DONE 0.0s # 3 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet: 5.0 # 3 sha256:3b35130338ebb888f84ec0aa58f64d182f10a676a625072200f5903996d93690 # 3 DONE 0.0s # 7 [1/3] FROM mcr.microsoft.com/dotnet/aspnet:5.0 # 7 sha256:31acc33a1535ed7869167d21032ed94a0e9b41bbf02055dc5f04524507860176 # 7 DONE 0.0s # 5 [internal] load build context # 5 sha256:2a74f859befdf852c0e7cf66b6b7e71ec4ddeedd37d3bb6e4840dd441d712a20 # 5 transferring context: 3.87MB 0.0s done # 5 DONE 0.1s # 4 [2/3] WORKDIR / app # 4 sha256:56abde746b4f39a24525b2b730b2dfb6d9688bcf704d367c86a4753aefff33f6 # 4 CACHED # 6 [3/3] COPY. / app # 6 sha256:4a3b76a4eea70c858830bad519b2d8faf5b6969a820b7e38994c2116d3bacab2 # 6 DONE 0.0s # 8 exporting to image # 8 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00 # 8 exporting layers 0.0s done # 8 writing image sha256:8867f4e2ed6ccddb509e9c39e86c736188a78f348d6487d6d2e7a1b5919c1fdb # 8 writing image sha256:8867f4e2ed6ccddb509e9c39e86c736188a78f348d6487d6d2e7a1b5919c1fdb done # 8 naming to registry.cn-hangzhou.aliyuncs.com/newbe36524/tyetest:1.0.0 done # 8 DONE 0.1s Created Docker Image: 'registry.cn-hangzhou.aliyuncs.com/newbe36524/tyetest:1.0.0' Pushing Docker Image... Pushed docker image: 'registry.cn-hangzhou.aliyuncs.com/newbe36524/tyetest:1.0.0' Validating Secrets... Generating Manifests...Deploying Application Manifests... Applying Kubernetes Manifests... Verifying kubectl installation... Verifying kubectl connection to cluster... Writing output to'C:\ Users\ Administrator\ AppData\ Local\ Temp\ tmp2BC2.tmp'. Deployed application 'tyetest'.Time Elapsed: 00VOL00VOUR 12VONING 99

From the output log, we can see that the application has been released successfully. And using K8s dashboard or K9s, we can see that the application has been successfully deployed and started.

Tyetest-674865dcc4-mxkd5 ●● 1 + 1 Δ 0 Running Δ 10.1.0.73 docker-desktop 3m46s

It is worth noting that there are several prerequisites to ensure that this step works properly:

You need to make sure that the local kubectl is configured correctly. Generally speaking, if you are using docker desktop, it is already configured

You need to make sure that docker login is successful. Developers can test whether the following images can be manually pushed before running the deployment

If the download speed of MCR image is not ideal, remember to use Newbe.McrMirror to accelerate.

Create and use ingress

At this point, we have completed the release of the application. However, since nginx ingress is not configured, the service can be run inside K8s, but it is not accessed externally. In other words, using the browser on the computer is still in a state that cannot be opened. Therefore, we also need to configure ingress for the service. Friends who have not yet installed ingress for K8s are advised to check out the previous chapter on installing K8s.

Here, we open tye.yml to add ingress-related configuration:

Name: tyetestregistry: registry.cn-hangzhou.aliyuncs.com/newbe36524services:-name: tyetest project: TyeTest/TyeTest.csprojingress:-name: tyetest-ingress bindings:-name: https protocol: https rules:-host: www.yueluo.pro service: tyetest

We have added an ingress configuration so that when traffic enters from ingress and the domain name is www.yueluo.pro, it will be forwarded to the tyetest service. In this way, the purpose of accessing the internal service of k8s from outside is realized.

First, you can check this effect locally using the tye run command. After running the command, you may see the following in dashboard:

Where https://localhost:8310 is the entry address of ingress. Because we use domain name binding, we can access it in two ways to verify the effect:

Add the mapping relationship of www.yueluo.pro-> 127.0.0.1 to hosts

Use http to request direct access to the file.

Here we use http to request direct access to the file:

GET https://localhost:8310/WeatherForecastHost: www.yueluo.pro

In this way, we have successfully verified the results of the binding.

Note that since the ports are not configured as fixed ports, developers should pay attention to the changes each time they run.

Deploy ingress to k8s

Next, stop tye run and run tye deploy to publish the ingress and application to K8s.

Note that the deployment of ingress can take tens of seconds, so you need to wait.

After the deployment is complete, you can view the deployment results through K8s dashboard or K9s.

Also, the following http requests can be used to verify the results of the deployment:

GET https://localhost/WeatherForecastHost: www.yueluo.pro

The result is the same as before.

Uninstall applications from K8s

Uninstall the application, very simple, tye undeploy.

PS C:\ Repos\ TyeTest > tye undeployLoading Application Details...Found 3 resource (s). Deleting 'Service'' tyetest'... Deleting 'Deployment'' tyetest'... Deleting 'Ingress'' tyetest-ingress'. Time Elapsed: 0000VOL02VIE87 after reading the above, do you have any further understanding of the installation and usage of Tye in K8s? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report