Deploy Tye’s sample application for microservices development tools to Azure Kubernetes Service

4 minute read

The other day, I wrote an article to try out the C # microservices development tool “Project Tye”.

https://tsubalog.hatenablog.com/entry/2020/08/02/234851


In the article the other day, I made a sample application with such a configuration.

–Front-end application (ASP.NET Core Razor Pages)
–Backend application (ASP.NET Core Web API + Redis)
–Tye configuration file (tye.yaml)

https://github.com/tsubakimoto/project-tye-sample


This time, I will deploy the sample application to Kubernetes according to Honke’s blog.

https://devblogs.microsoft.com/aspnet/introducing-project-tye/


Prepare Azure Kubernetes Service

First, prepare Kubernetes. This time, I’ll use Azure Kubernetes Service (AKS) quickly.
Please refer to the documentation for how to create an AKS resource.

https://docs.microsoft.com/ja-jp/azure/aks/kubernetes-walkthrough-portal


The Kubernetes version is verified with 1.16.10.
20200816012926.png


Build a deployment environment

Install these tools. I’m trying it on Ubuntu 20.04 on WSL2.


Azure CLI
https://docs.microsoft.com/ja-jp/cli/azure/install-azure-cli-apt?view=azure-cli-latest

kubectl
https://kubernetes.io/ja/docs/tasks/tools/install-kubectl/#curl%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6linux%E3%81%B8kubectl%E3%81%AE%E3%83%90%E3%82%A4%E3%83%8A%E3%83%AA%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B


Connect to AKS

Use the Azure CLI to get connection information to AKS.

$ az aks get-credentials --resource-group rg-project-tye --name aks-project-tye
Merged "aks-project-tye" as current context in /home/yuta/.kube/config

Deploy Redis to AKS

Deploy Redis for use in the sample application to AKS.
As per the blog, we will use the YAML file prepared in advance.

$ kubectl apply -f https://raw.githubusercontent.com/dotnet/tye/master/docs/tutorials/hello-tye/redis.yaml
deployment.apps/redis created
service/redis created

Also make sure it has been deployed.

$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
redis-58897bf8c-mrh9g   1/1     Running   0          5m2s

Deploy a sample application to AKS

Deploy the sample application to AKS using the Tye deploy command.
At this time, tye.yaml looks like this. (Same as the previous article)

# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
#    https://aka.ms/AA7q20u
#
name: microservice
services:
- name: backend
  project: backend\backend.csproj
- name: frontend
  project: frontend\frontend.csproj
- name: redis
  image: redis
  bindings:
  - port: 6379
    connectionString: "${host}:${port}"
- name: redis-cli
  image: redis
  args: "redis-cli -h redis MONITOR"

When deploying, a container image is created for each application that serves as a service.
Therefore, you need to specify the container registry that hosts the container image.

This time I used my Dockerhub account.

https://hub.docker.com/u/tsubakimoto


You will also be asked for the Redis connection string, so enter redis: 6379.

$ tye deploy --interactive
Loading Application Details...
Verifying kubectl installation...
Verifying kubectl connection to cluster...
Enter the Container Registry (ex: 'example.azurecr.io' for Azure or 'example' for dockerhub): tsubakimoto
Processing Service 'backend'...
    Applying container defaults...
    Compiling Services...
    Publishing Project...
    Building Docker Image...
        Created Docker Image: 'tsubakimoto/backend:1.0.0'
    Pushing Docker Image...
        Pushed docker image: 'tsubakimoto/backend:1.0.0'
    Validating Secrets...
        Enter the connection string to use for service 'redis': redis:6379
        Created secret 'binding-production-redis-secret'.
    Generating Manifests...
Processing Service 'frontend'...
    Applying container defaults...
    Compiling Services...
    Publishing Project...
    Building Docker Image...
        Created Docker Image: 'tsubakimoto/frontend:1.0.0'
    Pushing Docker Image...
        Pushed docker image: 'tsubakimoto/frontend:1.0.0'
    Validating Secrets...
    Generating Manifests...
Processing Service 'redis'...
    Applying container defaults...
        Service 'redis' does not have a project associated. Skipping.
    Compiling Services...
    Publishing Project...
        Service 'redis' does not have a project associated. Skipping.
    Building Docker Image...
        Service 'redis' does not have a project associated. Skipping.
    Pushing Docker Image...
        Service 'redis' does not have a project associated. Skipping.
    Validating Secrets...
    Generating Manifests...
        Service 'redis' does not have a container. Skipping.
Processing Service 'redis-cli'...
    Applying container defaults...
        Service 'redis-cli' does not have a project associated. Skipping.
    Compiling Services...
    Publishing Project...
        Service 'redis-cli' does not have a project associated. Skipping.
    Building Docker Image...
        Service 'redis-cli' does not have a project associated. Skipping.
    Pushing Docker Image...
        Service 'redis-cli' does not have a project associated. Skipping.
    Validating Secrets...
    Generating Manifests...
        Service 'redis-cli' does not have a container. Skipping.
Deploying Application Manifests...

        Verifying kubectl installation...
        Verifying kubectl connection to cluster...
        Writing output to '/tmp/tmph3XlUg.tmp'.
        Deployed application 'microservice'.
Time Elapsed: 00:00:59:77

Verify that the deployment has been done and the frontend, backend, and Redis pods have been created.

$ kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
backend-5d7b894dcf-2zjkd    1/1     Running   0          5m24s
frontend-84698d8fcf-xjglj   1/1     Running   0          5m24s
redis-58897bf8c-mrh9g       1/1     Running   0          42m

Check the deployed application

Port forward to port 80 of AKS and check that the application is running on http: // localhost: 5000 in your browser.

$ kubectl port-forward svc/frontend 5000:80
Forwarding from 127.0.0.1:5000 -> 80
Forwarding from [::1]:5000 -> 80

20200816013057.png


Delete the application deployed to AKS

Now that the sample application has been deployed to AKS and we’ve seen it in action, use Tye’s ʻundeploy` command to remove the application from AKS.

$ tye undeploy
Loading Application Details...
Found 7 resource(s).
Deleting 'Service' 'backend' ...
Deleting 'Service' 'frontend' ...
Deleting 'Service' 'redis' ...
Deleting 'Deployment' 'backend' ...
Deleting 'Deployment' 'frontend' ...
Deleting 'Deployment' 'redis' ...
Deleting 'Secret' 'binding-production-redis-secret' ...
Time Elapsed: 00:00:06:51
$ kubectl get pods
No resources found in default namespace.

Summary

I was able to deploy the sample microservices application to Kubernetes, all on the command line.

I think that the actual deployment to AKS is often done by preparing a CI / CD environment, but I thought that using Tye would be an ant at the timing of checking the operation at the stage of the development environment.