You'll need roughly 2 minutes to read this article.
To use Kubernetes with Codeship Pro, you will need to define a deployment container in your codeship-services.yml file with the
kubectl tool installed.
You can then use that service to run any
kubectl commands you need via your codeship-steps.yml file, as well as to authenticate with your production service.
Since many Kubernetes users are using a managed platform, such as Google, AWS or Azure we also have deployment containers pre-built to simplify this process.
Inside your codeship-services.yml file, you will need to define a new service with the
kubectl tool installed. For example:
app: build: ./ links: - postgres environment: user: admin cached: true
This service will need a Dockerfile, or an existing base image, that installs the tool and authenticates you either via environment variables or via hardcoded login credentials. The Dockerfile would look something like this, as a simple example:
FROM alpine:3.6 # Install kubectl # Note: Latest version may be found on: # https://aur.archlinux.org/packages/kubectl-bin/ ADD https://storage.googleapis.com/kubernetes-release/release/v1.6.4/bin/linux/amd64/kubectl /usr/local/bin/kubectl USER kubectl ENTRYPOINT ["/usr/local/bin/kubectl"]
Once you have your service defined, you will use your codeship-steps.yml file to run the necessary
kubectl commands. In this case, we will put those commands into a new script file named
- name: deploy service: app command: kubernetes.sh
Inside this script file can be any
kubectl commands you would like, for instance invoking a new Kubernetes deployment from a configuration file:
kubectl apply -f ./deployment.yaml
Essentially, now that you have a container with the
kubectl tool, you will script your deployments in any way you’d like to use that command line tool in the workflow you define.
For managed services, we have prebuilt deployment containers to simplify then authentication and deployment process and to make use of each provider’s individual CLI.
We also have a couple of code examples and sample projects available.