A new version of Newbe.Claptrap has recently been developed, using Tye to aid the development of k8s applications.Let's take a brief look at how it's used in this series.
First, make sure that the netcore 2.1 or above version of the dotnet SDK is installed correctly.
Tye is currently in development, so only the preview version can be installed for use at this time.The link below allows you to search for the latest version and copy the CLI installation on the interface.
Once installed, run tye in the console and you can see the following results：
Next we create a netcore app to test the deployment scenario.Choose a suitable location to run the following commands to create a test project：
That way, we get a test solution and a WebApi project.We can run the following command to start this service locally：
After launch, you can open thehttps://localhost:5001/swagger/index.htmlbrowser to see the startup swagger interface.
Next, let's close the previously running app and use tye instead to launch the test app locally.
In the solution directory, use the console to run the following commands：
After running, you may get the following results：
Follow the tips above to http://127.0.0.1:8000 the tye dashboard that started successfully on the computer.Open the dashboard using your browser to see a list of apps that have been deployed.As shown in the figure below：
Dashboard shows that the tester has started and is bound to http://localhost:14099 and https://localhost:14100.In practice, in self-testing, the two ports are randomly selected, so there will be differences.
By opening swagger with the https bindings exposed above, we can see the same effect as
Next, we'll use Tye to deploy the app to k8s.So in order to achieve this effect, you first need to prepare a k8s.
There are a variety of ways to deploy k8s on a development machine, and this experiment uses a Docker Desktop plus k8s scenario, either because of something else or because there are more or less problems with using other scenarios.Specific developers can choose.
The Docker Desktop s k8s scenario is well covered in the links below and is recommended for developers to refer to：
Docker Desktop Launches Kuberneteshttps://www.cnblogs.com/weschen/p/12658839.html
In addition to the k8s ontogene, this lab also requires the installation of nginx ingress and helm, which can also be installed with reference to the above article.
But when k8s is configured, we can use tye to quickly publish the app to k8s for viewing.
First, you need to configure docker registry for the local docker.Because the docker image of the project is packaged and pushed to a docker registry during the process of publishing with tye.
Developers can choose from a variety of ways to get their own docker registry：
- Nexus OSS Repository
- Alibaba Cloud, Tencent Cloud, DaoCloud, and more all have free docker registry
- Docker hub, if the network is good
docker loginto sign in to your docker registry.
In the solution catalog, run the following command to create a tye.yml profile:
After running, the following files will be created in the solution：
This is the simplest tye.yml file.
We add a line of configurations about docker registry in tye.yml to specify where the built-in image will be pushed：
For example, here the author is using the docker registry of the Hangzhou node of Alibaba Cloud, the namespace is newbe36524.So add a line
This is equivalent to, if built, a tag image of
registry.cn-hangzhou.aliyuncs.com/newbe36524/tyetest:1.0.0and pushed into the Alibaba Cloud.
Because this time we're releasing a netcore program, they're going to be built with netcore images, so for a smoother build, it's recommended that you use the acceleration tool to download the underlying image locally in advance.
For example, the application of net5 TFM used by my person in this use of this time, requires a base image to be pulled locally as mcr.microsoft.com/dotnet/aspnet:5.0.
Since the source of the netcore underlying mirror has now been migrated from docker hub to mcr.microsoft.com.Therefore, it is recommended to use Newbe.McMirror to expedite downloads.
Detailed usage methods can be referred to：https://github.com/newbe36524/Newbe.McrMirror
If the developer doesn't know what the underlying image they currently need to pull is, they can also try the following step to publish directly, view the underlying image content used in the process, and then pull.
Now that everything is ready, you can publish by continuing to run the following commands in the solution catalog:
You may get the following results:
From the log of the output, we can see that the app has been published successfully.And with k8s dashboard or k9s, we can all see that the app has been successfully deployed and started.
It is worth noting that there are several prerequisites for ensuring that this step：
- You need to make sure that your local kubectl is configured correctly.In general, if you are using docker desktop, it is already configured
- You need to make sure that the docker login has succeeded.Developers can test whether the following images can be pushed manually before running the deployment
- If the download speed of the MCR image is not ideal, remember to speed it up with Newbe.McRMirror
By this point, we've finished publishing the app.However, because nginx ingress is not configured, the service can already run inside k8s, but is not accessed externally.That is, using a browser on your computer is still not open.So we also need to configure ingress for the service.Friends who haven't installed ingress for k8s, it's recommended to review the previous sections on installing k8s.
Here, we turn on tye.yml to add ingress-related configuration：
We've added an ingress configuration so that when traffic comes in from ingress and the domain name is
www.yueluo.pro, it's forwarded to the tyetest service.This enables external access to the k8s internal services.
tye run command to see the effect locally.After you run the command, you may see the following in the dashboard：
Where, https://localhost:8310 is the entry address of ingress.Because we're using domain name binding, there are two ways to access it to verify the：
- Add a mapping relationship www.yueluo.pro> 127.0.0.1 in hosts
- Use http to request direct access to the file.
Here we use the http request file to access the：
In this way, we successfully validate the results of the binding.
Note that the ports in it are not configured as fixed ports, so each time the developer should pay attention to the changes that occur.
tye run, run
tye deployand publish ingress and applications to k8s.
Note that the deployment of ingress can take tens of seconds, so you need to wait.
Once the deployment is complete, you can view the results of the deployment through k8s dashboards or k9s.
Also, you can use the following http request to verify the results of your deployment：
The result is the same as it was before.
Uninstall the app,
simple, tye undeploy.
In this article, we briefly described the simple steps of how to run or deploy an app using tye.There are many options that can be extended and customized in practice.Interested friends can https://github.com/dotnet/tye in the content.
Next, we'll deploy some slightly more complex multi-instance applications.