Deployment Options for Kubernetes
Learn how to deploy to Kubernetes with the declarative deploy step
Codefresh offers a lot of options when it comes to Kubernetes deployments:
- Using the Codefresh GUI to deploy on demand. This is the easiest way and was described in the quick start guide.
- Using the dedicated deploy step in a pipeline. Explained in detail in the present page.
- Using the cf-deploy-kubernetes step in a pipeline. This can also perform simple templating on Kubernetes manifests.
- Using a freestyle step with Kustomize. Described in details in this page.
- Using a freestyle step with your own
kubectlcommands. This is very flexible, but assumes that you know how to work with
kubectl. Described in details in this page.
- Using Helm as a package manager. See the Helm quick start guide for more details.
It is assumed that
- You have already added your K8s cluster into Codefresh
- You are familiar with Codefresh YAML and basic pipeline steps and know how to describe it
- You know how to integrate your docker registry with Codefresh
Build and Push your image
The following describe a basic Codefresh pipeline scenario to build and push your image to Dockerhub registry.
Using this YAML example, we’ll add an additional step to deploy the image in Dockerhub to Kubernetes.
Describe your deployment
The following instructions describe how to create a new service in your Kubernetes cluster in order to deploy to it.
Note: If you’re deploying to an existing service in your Kubernetes cluster please skip to the next step
- Go to the
- Click the button “Add Service”.
- Select the cluster.
- Select the namespace.
- Type an arbitrary service name.
- Specify the number of replicas.
- Type the name of your pushed image.
- In the “Internal Ports” field specify the port which your application listens to.
- In the “Expose port” field specify the port to be exposed to the Internet and check the checkbox.
- Click the button “Deploy” to deploy the application.
Wait until the deployment is finished and you will be able to open the deployed application in your browser by clicking on the “endpoint” link.
Add a Deployment step
So now you have deployed your image manually, which is great. But how to trigger the deployment within your pipeline? For that you will need to add a step of a “Deploy” type to the Codefresh YAML manifest file:
The full Codefresh YAML looks like this:
You can now run the whole pipeline that builds your application from source to a docker image, pushes it to a docker registry and deploys it to your Kubernetes cluster.