Getting Started with Deployment
This tutorial assumes that you have completed the first step (run locally)
💡
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:
- Azure Kubernetes Service
- Kubernetes in Docker Desktop, however it does take up quite a bit of memory on your machine, so use with caution.
- Minikube
- K3s, a lightweight single-binary certified Kubernetes distribution from Rancher.
- Another Kubernetes provider of your choice.
⚠️ 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.
Deploying the application
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:
texttye deploy --interactiveEnter 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.
💡 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 deploydoes many different things to deploy an application to Kubernetes. It will:- Create a docker image for each project in your application.
- Push each docker image to your container registry.
- Generate a Kubernetes
DeploymentandServicefor each project. - Apply the generated
DeploymentandServiceto your current Kubernetes context.
Test it out!
You should now see two pods running after deploying.
textkubectl get podstextNAME READY STATUS RESTARTS AGE backend-ccfcd756f-xk2q9 1/1 Running 0 85m frontend-84bbdf4f7d-6r5zp 1/1 Running 0 85mYou'll have two services in addition to the built-in
kubernetesservice.textkubectl get servicetextNAME 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 3d5hYou can visit the frontend application by port forwarding to the frontend service.
textkubectl port-forward svc/frontend 5000:80Now 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.
💡 Currently
tyedoes not provide a way to expose pods/services to the public internet. We'll add features related toIngressin future releases.⚠️ 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.
Exploring tye.yaml
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.yamlRun the
tye initcommand in themicroservicesdirectory to generate a defaulttye.yamltexttye initThe contents of
tye.yamlshould look like:yaml# 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.csprojThe top level scope (like the
namenode) is where global settings are applied.tye.yamllists all of the application's services under theservicesnode. This is the place for per-service configuration.See schema for more details about
tye.yaml.💡 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.yamlBased on what container registry you configured, add the following line in the
tye.yamlfile:yamlregistry: <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 deploywithout--interactivesince the registry is stored as part of configuration.❓ 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.
Undeploying the application
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 undeployThis will remove all deployed resources. If you'd like to see what resources would be deleted, you can run:
tye undeploy --what-ifNext Steps
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).