Kubernetes

I would like to use octopus to manage deployments to our kubernetes cluster. Essentially it just needs to issue a few kubectl commands. I found something here: https://github.com/whereisaaron/octopus-kubectl I was wondering if someone has already tried this and can comment on how well this works.

Hi Jann,
Integrating container deployments with Octopus Deploy is an area that we have recently started investigating. While we now have support for basic Docker engine commands, we have unfortunately yet to move up the abstraction layers to provide first class support for orchestration tools like Kubernetes. Getting these sorts of comments from users like yourself help us to prioritise the future direction of Octopus and so we hope to start work on kubernetes steps soon.

The github link you provided sounds like an interesting approach to providing a containerized target for Octopus to connect in to perform the kubectl commands. Presumably the author of this image wanted to isolate the dependencies needed by Octopus to connect and run scripts (i.e. mono) however with the new raw Octopus feature it may not even be necessary. So long as you can ssh into a machine with kubectl installed you can run a raw script that issues the commands directly, without it needing to install mono or Calamari.

Our current plan is to probably provide a step, similar to the existing Docker steps, that issue the appropriate Kubernetes commands. Hopefully for the time being you will be able to script these commands out manually without too many issues and using the raw scripting, you may be able to avoid using the octopus-kubectl image entirely.

I hope these points help, let me know how you go. Keep an eye out for future support in this space.
Cheers,
Rob

Thanks Rob,
I was thinking the same thing that the kubectl docker image is not really necessary. I think I’ll just install kubectl on the octopus server and run the commands from there.

Will let you know how it goes.

Thanks,
Jann

Hi,
I managed to get it to work. I built a docker image containing the Octo tool. I had to modify the Octo launch script though to make it work. See below:

#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
cd -P "$( dirname "$SOURCE" )"
# LTTNG_UST_REGISTER_TIMEOUT=0 is there to work around a bug in docker that causes an assertion violation in dotnet on first launch
# See https://github.com/dotnet/cli/issues/1582
LTTNG_UST_REGISTER_TIMEOUT=0 dotnet Octo.dll $*

Hi Jann,
I’m glad to hear you got things working. The octo.exe image sounds like it could be an interesting tool for other users. Am I right in saying that you are running it in a Linux container with mono installed? How are you using it in your build pipeline?
Rob

Hi,
the patch above already got accepted into your source tree. So that should make it easier for other users. I’m running it on linux with dotnetcore.

See below for the dockerfile that I used. It has some specifics for our environment but it should be easy to make it work elsewhere.

I then use it in a Jenkinsfile like that:

def create_release(name, version) {
  def octo_env = docker.image('docker:5000/octopus/octopus-tools:4.13.4')
  octo_env.inside {
      withCredentials([string(credentialsId: 'OctopusAPIKey', variable: 'API_KEY')]) {
        sh "Octo create-release --server=http://<Octopus server URL> --apiKey=${API_KEY} --project=${name} --version=${version}"
      }
  }
}
FROM docker:5000/microsoft/dotnet:1.0.4-runtime

COPY OctopusTools.4.13.4.portable /opt/OctopusTools

RUN chmod +x /opt/OctopusTools/Octo && \
    ln -s /opt/OctopusTools/Octo /usr/local/bin/Octo

CMD /usr/local/bin/Octo

To deploy the image of my application using octopus I built a kubernetes plugin for octopus which I might contribute at some point.