docs/tutorials/hello-tye/01_deploy.md
This tutorial assumes that you have completed the first step (run locally)
:bulb:
tyewill use your current credentials for pushing Docker images and accessing kubernetes clusters. If you have configured kubectl with a context already, that's whattye deployis going to use!
Before we deploy, make sure you have the following ready...
Installing docker based on your operating system.
A container registry. Docker by default will create a container registry on DockerHub. You could also use Azure Container Registry or another container registry of your choice, like a local registry for testing.
A Kubernetes Cluster. There are many different options here, including:
:warning: If you choose a container registry provided by a cloud provider (other than Dockerhub), you will likely have to take some steps to configure your kubernetes cluster to allow access. Follow the instructions provided by your cloud provider.
Now that we have our application running locally, let's deploy the application. In this example, we will deploy to Kubernetes by using tye deploy.
Deploy to Kubernetes
Deploy the application by running:
tye deploy --interactive
Enter the Container Registry (ex: 'example.azurecr.io' for Azure or 'example' for dockerhub):
You will be prompted to enter your container registry. This is needed to tag images, and to push them to a location accessible by kubernetes.
:bulb: Under the hood
tyeuseskubectlto execute deployments. In cases where you don't havekubectlinstalled or it's current context is invalidtye deploywill fail with the following error: "Drats! 'deploy' failed: Cannot apply manifests because kubectl is not installed."
If you are using dockerhub, the registry name will be your dockerhub username. If you use a standalone container registry (for instance from your cloud provider), the registry name will look like a hostname, eg: example.azurecr.io.
tye deploy does many different things to deploy an application to Kubernetes. It will:
Deployment and Service for each project.Deployment and Service to your current Kubernetes context.Test it out!
You should now see two pods running after deploying.
kubectl get pods
NAME READY STATUS RESTARTS AGE
backend-ccfcd756f-xk2q9 1/1 Running 0 85m
frontend-84bbdf4f7d-6r5zp 1/1 Running 0 85m
You'll have two services in addition to the built-in kubernetes service.
kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
backend ClusterIP 10.0.147.87 <none> 80/TCP 11s
frontend ClusterIP 10.0.20.168 <none> 80/TCP 14s
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 3d5h
You can visit the frontend application by port forwarding to the frontend service.
kubectl port-forward svc/frontend 5000:80
Now navigate to http://localhost:5000 to view the frontend application running on Kubernetes. You should see the list of weather forecasts just like when you were running locally.
:bulb: Currently
tyedoes not provide a way to expose pods/services to the public internet. We'll add features related toIngressin future releases.
:warning: Currently
tyedoes not automatically enable TLS within the cluster, and so communication takes place over HTTP instead of HTTPS. This is typical way to deploy services in kubernetes - we may look to enable TLS as an option or by default in the future.
Tye has a optional configuration file (tye.yaml) to allow customizing settings. If you want to use tye deploy as part of a CI/CD system, it's expected that you'll have a tye.yaml.
Scaffolding tye.yaml
Run the tye init command in the microservices directory to generate a default tye.yaml
tye init
The contents of tye.yaml should look like:
# 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:
# <survey link>
#
name: microservice
services:
- name: frontend
project: frontend/frontend.csproj
- name: backend
project: backend/backend.csproj
The top level scope (like the name node) is where global settings are applied.
tye.yaml lists all of the application's services under the services node. This is the place for per-service configuration.
See schema for more details about tye.yaml.
:bulb: We provide a json-schema for
tye.yamland some editors support json-schema for completion and validation of yaml files. See json-schema for instructions.
Adding a container registry to tye.yaml
Based on what container registry you configured, add the following line in the tye.yaml file:
registry: <registry_name>
If you are using dockerhub, the registry_name will your dockerhub username. If you use a standalone container registry (for instance from your cloud provider), the registry_name will look like a hostname, eg: example.azurecr.io.
Now it's possible to use tye deploy without --interactive since the registry is stored as part of configuration.
:question: This step may not make much sense if you're using
tye.yamlto store a personal Dockerhub username. A more typical use case would be storing the name of a private registry for use in a CI/CD system.
After deploying and playing around with the application, you may want to remove all resources associated from the Kubernetes cluster. You can remove resources by running:
tye undeploy
This will remove all deployed resources. If you'd like to see what resources would be deleted, you can run:
tye undeploy --what-if
Now that you are able to deploy an application to Kubernetes, learn how to add a non-project dependency to tye with the next step (add Redis).