Use kubectl as part of Freestyle step

How to run manually kubectl in a Codefresh pipeline

Running Kubernetes commands in Codefresh as part of the workflow is very easy.

Codefresh is adding all your clusters into the workflow ready to be used as part of your CI/CD pipeline. The context remains the same as it appears in the Codefresh Kubernetes dashboard.

If your cluster name includes spaces then make sure that you use quotes in the kubectl command.

  • Use image: codefresh/kubectl
  • Add your commands:
    • kubectl config get-contexts. Will print the cluster that we added to the workflow
    • kubectl config use-context "my-cluster-name". The name is the same as in Account settingsIntegrationsKubernetes
    • kubectl get po -owide
    • kubectl get nodes

Follow the example

  • Add this Git repo to your account
  • Change the pipeline configuration to use codefresh.yml.
  • Build.

Running parallel steps with kubectl

More complex examples can be found in the custom kubectl commands documentation page.