Running custom kubectl commands
How to use kubectl in your Codefresh pipelines
As explained in the deployment options page, Codefresh has several built-in facilities for deploying to Kubernetes clusters.
If you wish you can still run your own custom
kubectl commands in a freestyle step for maximum flexibility on cluster deployments. Kubectl is the command line interface for managing kubernetes clusters.
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 of the most up-to-date version.
If you run the pipeline you will 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 are going to create two docker images and deploy them into two separate clusters, using custom
kubectl commands. We are going also to use the parallel capability of Codefresh pipelines.
Here is the pipeline:
and here is the full
In this example above we select the one of the clusters on each deployment step, and then apply several Kubernetes manifests that constitute an application.