Credit: Kubernetes
teracy-dev
is developed with the goal to keep it as minimal and extensible as possible.
The extension feature is so powerful that you can customize the VM in anyway you want. For example,
in this blog post, I’ll show you how to extend it to work with Kubernetes.
About Kubernetes
We’re leveraging Docker for all of our development workflow for our clients, internal and open
source projects. teracy-dev
is provisioned with Docker by default out of the box so that we can
start working with Docker right away.
However, Docker alone is not enough to work with container technology stack. The production deployment is different from the local Docker environment. There are many options for container production deployment, however, we choose Kubernetes as the first class as it’s currently the big giant and the future of container orchestration that we believe in.
Working with Kubernetes requires kubectl
client to be available, and if you’re starting to use
GKE (Google Container Engine), gcloud
(google cloud sdk) client should be available, too.
So let’s find a way to extend teracy-dev
to install kubectl
and gcloud
.
Extending teracy-dev
You can extend teracy-dev
’s VM by your own choice of operating system and automate the provisioning
process by your own choice of configuration software. “The only limit is your imagination” :–).
To extend teracy-dev
, we can use any kind of provisioners that are supported by vagrant (as teracy-dev
is built on top of vagrant
), you can see more info here: https://www.vagrantup.com/docs/provisioning/
We choose Chef
as it’s our default provisioner that we have more years of usage experience. We intend
to use Ansible
for some future projects, too.
Installing ChefDK
We’re going to use Acme 101
project which is used to show the best practices from teracy-dev
applied
for organizations.
To work with Chef cookbooks, we need to install ChefDK
. Fortunately, there is already an available cookbook
for us to use to install ChefDK
automatically on our VM: https://supermarket.chef.io/cookbooks/chef-dk
Usually, we have dev-setup
directory to extend teracy-dev
(acme-dev
in this case). The initial
dev-setup
content should be like this: https://github.com/acme101/kubernetes-dev-setup/tree/0-initial
To install ChefDK
, we must install the chef-dk
cookbook and use it as follows:
Add
depends 'chef-dk'
todev-setup/chef/main-cookbooks/acme/metadata.rb
Install vendor cookbooks with the following commands within the VM:
1 2 3 |
|
- Sync back the changes from the VM to the host machine:
1
|
|
The updated content should be like this: https://github.com/acme101/kubernetes-dev-setup/tree/1-dependency
Now, to install chef-dk
, just add the following Ruby code to default.rb
recipe, it’s never so easy:
1 2 3 4 |
|
Make sure you have berks-cookbooks
paths that vagrant
can look up. The configuration step should
be like this: https://github.com/acme101/kubernetes-dev-setup/tree/2-configuration
- After that,
$ vagrant reload --provision
and voila, you should haveChefDk
installed.
1 2 3 4 5 6 7 8 |
|
That’s how we use Chef cookbooks to manage the VM’s software automatically. We can do the same with all other types of Chef cookbooks shared and opensourced from the public Chef Supermarket: https://supermarket.chef.io/ You can use all the public shared cookbooks to do almost anything you want for your VM.
However, sometimes, there is not available cookbook that we want, then it’s time we should build new cookbooks from scratch.
Creating new Chef cookbooks
From the steps above, we have ChefDK
available to work with Chef cookbooks. To learn how to use it,
you can follow: https://github.com/chef/chef-dk
I already created the initial kubernetes-stack-cookbook
that we can work with. You need to clone
the repo into the workspace
directory:
1 2 |
|
You can test the cookbook within the VM ($ vagrant ssh
) with rspec
, kitchen
easily:
1 2 3 |
|
you should see the following similar content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
and to test with kitchen
:
1 2 3 4 |
|
then you should see the following similar content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
That’s how we develop and test the cookbook on local dev.
You can see the cookbook here at https://github.com/teracyhq-incubator/kubernetes-stack-cookbook
It’s currently a very simple cookbook to support the installation of kubectl
and gcloud
. In
the future, it will do more than that and support more platforms than current Ubuntu only.
Installing kubectl
and gcloud
The kubernetes-stack-cookbook
is not available on the Chef Supermarket (yet), so to use it, we need
to install it from the github repo.
To install kubectl
, add this to the default.rb
recipe:
1
|
|
To install gcloud
, add this to the default.rb
recipe:
1
|
|
The configuration step should be like this: https://github.com/acme101/kubernetes-dev-setup/tree/3-kubectl-gcloud-installation
After that, $ vagrant reload --provision
and voila (again), you should have both of the packages installed.
1 2 3 |
|
1 2 3 4 5 6 7 8 |
|
Setting up Kubernetes local deployment
I’ve shown you how to extend teracy-dev
to install new software packages. It is very simple, just follow
the steps I described above to apply for all other projects.
kubectl
and gcloud
are used to work with Google Container Engine (GKE), however, we want
to install Kubernetes to test on local dev, too. So I will have another blog post to cover this more
complex setup: how to create a Kubernetes cluster to work on local dev so that we can test all your
production Docker images on your local dev the same way it is deployed on the production system.
Summary
Now you should know how to extend teracy-dev
with Chef cookbooks, this is a very common task to do.
And other newcomer devs can just use your dev-setup
without learning anything new, just follow
the instructions and learn more to master later.
There are still some areas of configuration for teracy-dev
that needs improvement and it will be
available on teracy-dev
v0.5.0, so stay tuned for our next very exciting upcoming releases.
I hope that this blog post can help you follow the current best practices to extend teracy-dev
for your own need more easily. If you have any problem with it, let me know by dropping your comments.
Happy hacking!