This example shows how to deploy Kubernetes configuration consisting of two Deployments with different number of containers: deployment1 (2 containers) and deployment2 (1 container).
- Fabricio 0.5 or greater
- Vagrant
- One from the list of Vagrant supported providers (this example was tested with VirtualBox)
- fabfile.py, Fabricio configuration
- configuration.yml, Kubernetes configuration file
- kube-canal.yml, networking configuration for Kubernetes
- kube-rbac.yml, RBAC configuration for Kubernetes
- README.md, this file
- Vagrantfile, Vagrant config
Run vagrant up
and wait until VMs will be created.
fab --list
Before proceed you have to initialize Kubernetes cluster first by running following command:
fab k8s-init
Note: use fab k8s-reset
to reset cluster
After cluster has been successfully initialized everything is ready to work with Kubernetes configurations:
fab service
Fabricio tries to deploy Kubernetes configuration either if content of provided configuration file was changed or any image of the configuration has newer version since last successful deploy attempt. However configuration deploy can be forced by using force
flag:
fab service:force=yes
Any Fabricio command can be executed in parallel mode. This mode provides advantages when you have more then one host to deploy to. Use --parallel
option if you want to run command on all hosts simultaneously:
fab --parallel service
Try to update configuration file (configuration.yml
) and run deploy again:
fab service
This will update Kubernetes configuration using new configuration file. After that you can return Kubernetes configuration to previous state by running 'rollback' command:
fab service.rollback
See also "Hello World" Customization section.
Custom configuration file can be provided using filename
option:
from fabricio import kubernetes, tasks
service = tasks.DockerTasks(
service=kubernetes.Configuration(
name='my-service',
options={
'filename': 'custom-configuration.yml',
},
),
)
filename
option (as well as any other option) can be a callable taking kubernetes.Configuration
instance as parameter:
from fabric import api as fab
from fabricio import kubernetes, tasks
def filename(
configuration, # type: kubernetes.Configuration
):
# select configuration depending on infrastructure name
# (see 'Infrastructures and roles' example)
return '%s-configuration.yml' % (fab.env.infrastructure or 'default')
service = tasks.DockerTasks(
service=kubernetes.Configuration(
name='my-service',
options={
'filename': filename,
},
),
)