CiscoCloud / kubernetes-ansible

Install and configure Google Kubernetes on OpenStack
Apache License 2.0
82 stars 37 forks source link

Install and configure Kubernetes on OpenStack using ansible and terraform

Main goals

Available Addons

NOTE

Each addon is enabled by default but can be disabled by changing the options within group_vars/all.yml All of the addons depend on the DNS addon for Service Discovery.

Provision Openstack environment

When following the instructions in this section, replace PROJECT with the lowercase name of the client to install, such as nova. Repeat for each client. The following values are valid:

    - barbican - Key Manager Service API
    - ceilometer - Telemetry API
    - cinder - Block Storage API and extensions
    - glance - Image service API
    - heat - Orchestration API
    - magnum - Containers service API
    - manila - Shared file systems API
    - mistral - Workflow service API
    - murano - Application catalog API
    - neutron - Networking API
    - nova - Compute API and extensions
    - sahara - Data Processing API
    - swift - Object Storage API
    - trove - Database service API
    - tuskar - Deployment service API
    - openstack - Common OpenStack client supporting multiple services

    # How to install with pip:
    pip install python-PROJECTclient
    (Replace PROJECT with the lowercase name of the client)

    # How to update with pip:
    pip install --upgrade python-PROJECTclient
    (Replace PROJECT with the lowercase name of the client)

    # To remove the client, run the pip uninstall command:
    pip uninstall python-PROJECTclient
    (Replace PROJECT with the lowercase name of the client)

Additional OpenStack CLI information here

Note: You must use image with pre-installed cloud-init.

Firewall notice

If you are running on a cloud provider make sure that firewall configuration permits traffic between nodes. If you used terraform to provision environment then a security group has already been created for you.

Port list on roles: TBD

Prepare environment

There is 3 main roles:

You can safely combine etcd and kubernetes master on one host, eventually you can run kubernetes minion on that host also.

For this setup you will need 1 host that would be kubernetes master and 2 or more hosts as minions. At least 2 minion nodes are needed to use flannel or any other networking for kubernetes.

If you already have prepared hosts you can provide simple ansible inventory (sample is in root of project).

Run ansible playbooks

Use Getting started with Ansible if you are not familiar with ansible.

Verify that ansible can reach your hosts.

ansible -m ping all

Validate the global configurations found in group_vars/all.yml and update as needed.

To run ansible on hosts you prepared run:

ansible-playbook -i inventory setup.yml

If you used Terraform to provision your hosts, a plugin is provided that dynamically extracts the inventory from .tfstate file.

ansible-playbook setup.yml

The same plugin can be used to either print out a lists of hosts or to add those hosts to your local /etc/hosts file so that you can reference the hosts by name.

The following command will append the hosts to your /etc/hosts file.

./plugins/inventory/terraform.py --hostfile >> /etc/hosts

Validate Ansible playbooks

Install Serverspec environment :

bundle install --path vendor/bundle

Run Serverspec test for all nodes and specs in parallel (using 8 threads), print short summary in JSON format and provide 0 exit code for succeed validation of Ansible playbooks :

bundle exec rake -m -j 8

Run Serverspec tests for different plays in parallel :

bundle exec rake spec:play:All -m -j 8
bundle exec rake spec:play:Master -m -j 8
bundle exec rake spec:play:Node -m -j 8

Show all available Rake-tasks :

bundle exec rake -T

To use different RSpec output formats (json is default one) :

FORMAT=documentation bundle exec rake spec:play:All -m -j 8
FORMAT=json bundle exec rake spec:play:All -m -j 8
FORMAT=progress bundle exec rake spec:play:All -m -j 8
JSON output format

When using FORMAT=json (default) the output will contain tests summary only :

{
  "succeed": true,
  "example_count": 490,
  "failure_count": 0
}

Detailed results could be found inside serverspec_results.json file at project root directory :

[
  {
    "name": "docker::k-master-01",
    "exit_code": 0,
    "output": {
      "version": "3.4.0",
      "examples": [
        {
          "description": "should be installed",
          "full_description": "docker : Main | Package \"docker\" should be installed",
          "status": "passed",
          "file_path": "./roles/docker/spec/main_spec.rb",
          "line_number": 5,
          "run_time": 3.202775,
          "pending_message": null
        },
        {
          "description": "should be enabled",
          "full_description": "docker : Main | Service \"docker\" should be enabled",
          "status": "passed",
          "file_path": "./roles/docker/spec/main_spec.rb",
          "line_number": 9,
          "run_time": 0.443939,
          "pending_message": null
        }
      ],
      "summary": {
        "duration": 4.07774,
        "example_count": 3,
        "failure_count": 0,
        "pending_count": 0
      },
      "summary_line": "3 examples, 0 failures"
    }
  },
  {
    "name": "flannel::k-master-01",
    "exit_code": 0,
    "output": {
      "version": "3.4.0",
      "examples": [
        {
          "description": "should be installed",
          "full_description": "flannel : Main |  Service | Package \"flannel\" should be installed",
          "status": "passed",
          "file_path": "./roles/flannel/spec/main_spec.rb",
          "line_number": 6,
          "run_time": 3.253822,
          "pending_message": null
        }
      ],
      "summary": {
        "duration": 6.399068,
        "example_count": 10,
        "failure_count": 0,
        "pending_count": 0
      },
      "summary_line": "10 examples, 0 failures"
    }
  }
]

Check cluster deployment

Validate Control

Validate Nodes