Testing Anchore with Ansible, k3s and Vagrant

When I began here at Anchore, I realized I would need to create a quick and offline way to be able to test an installation in a way that would better approximate the most common way it is deployed: on Kubernetes.

We have guides to stand up anchore with docker-compose, and how to launch into Amazon EKS, but we didn’t have a quick way to test our helm chart, and other aspects of our application, locally on a laptop in a way that used k3s instead of minikube.

I also wanted to stand up a quick approximation not just on my local laptop, but against various other projects I have. So I created a k3s project base that automatically deploys k3s in vagrant and virtualbox locally on my laptop. Also, if I need to stand up a kubernetes cluster on external hosts to my laptop, I can run the playbook against those hosts to stand up a k3s cluster and deploy the anchore engine helm chart.

To get started, you can check out my project page on github. It’s not a feature complete project yet, but pull requests are always welcome.

Scenario 1: Standing this up on your local laptop.

Step 1: Install the dependencies.

To use this, just make sure you’ve met the requirements for your laptop, which is to say: make sure you have ansible, vagrant and virtualbox installed. Clone the repo, change directories into that repo and issue the command “vagrant up”. There’s more details on the readme file to help get you started.

First, you’ll need to be running a linux or MacOS laptop and have the following things installed:
Virtualbox v5.2 or later
Vagrant v2.0 or later
The Vagrant Virtualbox Guest Additions Plugin
Ansible v2.7 or later
A copy of the project repository (git clone.)

First install Virtualbox per the link instructions above. Once that is in place, install Ansible and Vagrant per the links above also. To install the Vagrant VirtualBox Guest Additions Plugin, you issue the following command:

vagrant plugin install vagrant-vbguest

We are now ready to clone the repository and get this running. The following three commands will pull the repository and stand up the k3s cluster:

git clone https://github.com/dfederlein/k3s_project_base.git
cd k3s_project_base
vagrant up

Scenario 2: Run this playbook against hosts external to your laptop.

In this scenario, you have ansible installed on a control host, and you will be building a k3s cluster of hosts you already control. I will assume this scenario is utilized by people already familiar with ansible and give some shortcut notes.

First, clone the repository with the following command:

git clone https://github.com/dfederlein/k3s_project_base.git

Next we’ll modify the hosts.ini file to reflect the hosts you want to create this cluster on. Once you’ve added those, the following command should get you what you need:

ansible-playbook -i hosts.ini site.yml -u (user)

Add the become password and connection password or private key flags to that command as needed. More information on how to do that in the ansible documentation.

The end of the processes detailed above should have a working k3s cluster running on your laptop, or on the external hosts you’ve pointed the playbook at, and a helm chart of anchore deployed to that cluster. Please note that the Vagrant/local deploy scenario may need some patience after being created, as it will operate with limited ram and resources.

As always, if you have questions please join us in our community slack.

Try Anchore Today

Get started with the Open Source Anchore Engine

Sign up for news and updates

Get notified of new features, tips & tricks, articles and more.  Just enter your name and email and we will take care of the rest.