Create your own Kubernetes cluster
- Vagrant v2.2.8
- Virtualbox v6.1.6
- Ansible v2.9.7
- Vagrant DigitalOcean v0.9.5
- Direnv v2.21.2
ensure you have the specified version or above for all the above mentioned tools
- Vagrant
$ brew cask install vagrant
- Virtualbox
$ brew cask install virtualbox
- Ansible
$ brew install ansible
- Vagrant DigitalOcean
$ vagrant plugin install vagrant-digitalocean
- Direnv
$ brew install direnv
Make sure to hook direnv into your shell.
If you are using bash
shell, then add the following line at the end of the ~/.bashrc file:
eval "$(direnv hook bash)"
If you are using zsh
shell, then add the following line at the end of the ~/.zshrc file:
eval "$(direnv hook zsh)"
for other shell, refer here
Note, if you are have spwaned multiple tabs / windows / split of your terminal, whenever you make changes to .envrc ensure to press just enter in all the instances to loaded the updated environment variables into the instance of the terminal window
failing to do will result in undesired output
When you provision a cluster, a kubeconfig file generated with
$USER-$CLUSTER_NAME_PREFIX
.conf and placed inside$HOME/.kube/configs
, ensure to backup the file if one exists in the path
As a first step, setup necessary env variables.
In DigitalOcean,
- Follow the instruction here to setup personal token
- Follow the instruction here to upload your ssh key to your digital ocean account
$ cp .envrc.sample .envrc
- Modify the following configurations as per your credentials
DIGITAL_OCEAN_TOKEN: the token your have created in step 1
DIGITAL_OCEAN_SSH_KEY_NAME: the ssh key you have created in step 2
DIGITAL_OCEAN_PRIVATE_KEY: private_key_file_name (assumption is the file will be located under $HOME/.ssh/private_key_file_name) for which you have uploaded the public key in step 2
- Load the env variables
## This command has to be run for every change in .envrc
$ direnv allow .
- Validate the configuration
$ make validate
- Use digitalocean based cluster
$ make use.digitalocean
Additionally, if you are using ZSH shell instead of bash
## Only for ZSH
$ eval "$(direnv hook zsh)"
- Verify the configuration before proceeding futher
$ make validate
- To create the cluster,
$ make provision.cluster
- To access the cluster, set the KUBECONFIG environment variable as
$ export KUBECONFIG=$HOME/.kube/configs/${USER}-${CLUSTER_NAME_PREFIX}.conf
- To teardown the cluster, execute
$ make destroy
- By default, VMs are created with 4vCPUs and 8GB of RAM. To change this use the configuration parameter
INSTANCE_TYPE
.
## default instance type
INSTANCE_TYPE: s-4vcpu-8gb
## For more info, visit https://developers.digitalocean.com/documentation/changelog/api-v2/new-size-slugs-for-droplet-plan-changes/
- For setting up VirtualBox, the following configuration needs to be set in .envrc file.
K8S_PROVIDER: virtualbox
- Use virtualbox based cluster
$ make use.virtualbox
- To setup k8s cluster locally using virtualbox, execute
$ make provision.cluster
- Validate the configuration
$ make validate
- Use virtualbox based cluster
$ make use.virtualbox
- To access the cluster, set the KUBECONFIG environment variable as
$ export KUBECONFIG=$HOME/.kube/configs/${USER}-${CLUSTER_NAME_PREFIX}.conf
- To teardown the cluster, execute
$ make destroy
The same scripts can be used to create a systems
cluster.
make switch.systems
make provision.cluster
To switch back to old cluster,
make switch.k8s
Issue with Digital ocean authentication
If you face the following issue when issuing make
, vagrant
commands for managing kubernetes cluster in digitalocean,
There was an issue with the JSON response from the DigitalOcean
API at:
Path: /v2/droplets
URI Params: {}
The response JSON from the API was:
Response: Unable to authenticate you
simple source the .envrc file once. ($ source .envrc
), also ensure your .envrc configurations are correct or use direnv as mentioned in the Prerequisite
Issue with bcrypt_pbkdf
If you face this issue, probably you are using ssh with passphrase ensure you have configured ssh-agent, for more info refer here
To deploy dobby app
kubectl apply -f https://raw.githubusercontent.com/thecasualcoder/dobby/master/examples/kubernetes/deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/thecasualcoder/dobby/master/examples/kubernetes/service.yaml