Deployment with DevSpace
Once you are done with developing your application or you just want to test if it works even outside of development mode with your actual container image, you can start a clean deployment.
#
Kube-Context & NamespaceFor this clean deployment, you may want to switch to a different namespace or even to a different cluster to test your application in a cloud-powered cluster, for example.
- Local Cluster
- Remote Cluster
Local Clusters
Local clusters run on your local dev machine and include: minikube, kind, k3s, mikrok8s etc.
If you want to deploy to a local Kubernetes cluster, make sure your current kube-context points to this cluster and tell DevSpace which namespace to use:
Kube-Context Namespace
Running the command above will change the default namespace of your kube-context, i.e. instead of using the default
namespace, kubectl
and other tools will now use a different namespace when working with this kube-context. That also means, you will not always need to use the --namespace / -n
flag.
Remote Clusters
Remote clusters run in a cloud or private data center and include: GKE, EKS, AKS, bare metal etc.
- Use cluster alone
- Share cluster with others
Kube-Context Namespace
Running the command above will change the default namespace of your kube-context, i.e. instead of using the default
namespace, kubectl
and other tools will now use a different namespace when working with this kube-context. That also means, you will not always need to use the --namespace / -n
flag.
#
Kubernetes multi-tenancyOne of the options for setting up a multi-tenant Kubernetes environment would be to use Loft. It allows the developers to create isolated Kubernetes environments in a self-service fashion.
Loft offers a wide range of features to facilitate multi-tenancy in Kubernetes. One of such features is the ability to create Virtual Clusters - a lightweight, fully functional and certified Kubernetes distribution that runs fully within the host cluster.
Loft also adds a resource called "Space" into your Kubernetes cluster. A "Space" is a virtual representation of a Kubernetes namespace, and we will be creating one in the steps below.
#
How to use Loft STEP 1#
Setup Loft and connect your clusterSee the Loft getting started guide for details.
STEP 2
#
Install the Loft plugin for DevSpaceSTEP 3
#
Login to Loft via DevSpaceSTEP 4
#
Create isolated namespaces (= Spaces)Kube-Context
DevSpace automatically sets up a kube-context for this Space, so you can also access your namespace using kubectl
, helm
or any other Kubernetes tool. Try it:
STEP 5
#
Add cluster users and allow them to create SpacesLearn more about how to do this in the Loft documentation.
#
Deploy ProjectRun the local deployment pipeline using this command:
Running devspace deploy -p production
will do the following:
- Build the Dockerfile(s) specified in the
images
section of thedevspace.yaml
- Tag the resulting image(s) with an auto-generated tag according to a customizable tag schema
- Push the resulting Docker images to the specified registries
- Create image pull secrets in your Kubernetes namespace (optional, enabled by default)
- Deploy everything that is defined within the
deployments
section in thedevspace.yaml
Image Building Only
If you only want to build, tag and push all images but not deploy anything, run:
#
Understand ProfilesAs shown earlier, DevSpace is by default configured to skip image building, for example. However, to fully test your containerized application you may want to create a fresh image and push this image to a registry.
Profiles allow you to apply modifications to your devspace.yaml
configuration for certain use cases or for different deployment targets (e.g. dev vs testing vs production).
By default, devspace init
adds a small example profile called production
which only removes the disabled: true
statement from our images
section which in turn enables image building:
You can print the config after a profile has been applied to see what the profile actually changes:
The flag -p / --profile
is global, so we can also use them for other commands and define profiles that apply to different workflows for commands such as devspace dev
: