Custom kubectl commands
Use kubectl in your Codefresh pipelines
As described in Deployment options for Kubernetes, Codefresh has built-in functionality for deploying to Kubernetes clusters.
Codefresh automatically sets up your config context with your connected clusters.
The config context is automatically placed for you at the path of the variable
In the current Codefresh implementation, this expands to
/codefresh/volume/sensitive/.kube/config, within the shared step volume.
When you use custom
kubectl commands, it is your responsibility to template your manifests using any of the available options. To employ Codefresh for templating, it is better to use the dedicated cf-deploy-kubernetes step, which provides simple templating capabilities.
Using the Codefresh kubectl image
Codefresh already offers a public Docker image with
kubectl at https://hub.docker.com/r/codefresh/kubectl/tags. You can choose a specific version of
kubectl with the appropriate tag or just select
latest for the most up-to-date version.
If you run the pipeline, you can see the help options for
Getting a config context
If you run this pipeline, you will see the names of all your connected clusters:
With two sample clusters, the output of this pipeline is the following:
Running freestyle step: Running Kubectl Pulling image codefresh/kubectl:latest Status: Image is up to date for codefresh/kubectl:latest NAME CLUSTER AUTHINFO NAMESPACE gke-kostisdemo-codefresh-kostis gke-kostisdemo-codefresh-kostis gke-kostisdemo-codefresh-kostis default kostis-demo@FirstKubernetes kostis-demo@FirstKubernetes kostis-demo@FirstKubernetes default
You can modify the current config context and run any
kubectl command you want applied to that context. The next pipeline will print all the nodes of the first cluster:
Example of parallel deployment with kubectl
Let’s see a full example. In this pipeline, we will create two Docker images and deploy them on two separate clusters, using custom
kubectl commands. We will also use the parallel capability of Codefresh pipelines.
Here is the pipeline:
And here is the complete
In the example above, we select one of the clusters in each deployment step, and then apply several Kubernetes manifests that constitute an application.