Reader small image

You're reading from  Kubernetes - A Complete DevOps Cookbook

Product typeBook
Published inMar 2020
PublisherPackt
ISBN-139781838828042
Edition1st Edition
Concepts
Right arrow
Author (1)
Murat Karslioglu
Murat Karslioglu
author image
Murat Karslioglu

Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
Read more about Murat Karslioglu

Right arrow

Configuring a Kubernetes cluster using Ansible

Powerful IT automation engines such as Ansible can be used to automate pretty much any day-to-day IT task, including the deployment of Kubernetes clusters on bare-metal clusters. In this section, we will learn how to deploy a simple Kubernetes cluster using Ansible playbooks.

Getting ready

    In this recipe, we will use an Ansible playbook. The examples that will be used in these recipes are accessible through the k8sdevopscookbook GitHub repository.

    Before you start executing the commands in this section's recipes, clone the Ansible playbook examples using the following command:

    $ git clone https://github.com/k8sdevopscookbook/src.git

    You will find the examples stored under the k8sdevopscookbook/src directory.

    How to do it…

    This section will take you through how to configure a Kubernetes cluster using Ansible. To that end, this section is further divided into the following subsections to make this process easier:

    • Installing Ansible
    • Provisioning a Kubernetes cluster using an Ansible playbook
    • Connecting to the Kubernetes cluster

    Installing Ansible

    In order to provision a Kubernetes cluster using an Ansible playbook, follow these steps:

    1. To install Ansible on your Linux workstation, first, we need to add the necessary repositories:
    $ sudo apt-get install software-properties-common
    $ sudo apt-add-repository --yes --update ppa:ansible/ansible
    1. Install Ansible using the following command:
    $ sudo apt-get update && sudo apt-get install ansible -y
    1. Verify its version and make sure Ansible is installed:
    $ ansible --version

    At the time this recipe was written, the latest Ansible version was 2.9.4.

    Provisioning a Kubernetes cluster using an Ansible playbook

    In order to provision a Kubernetes cluster using an Ansible playbook, follow these steps:

    1. Edit the hosts.ini file and replace the master and node IP addresses with your node IPs where you want Kubernetes to be configured:
    $ cd src/chapter1/ansible/ && vim hosts.ini
    1. The hosts.ini file should look as follows:
    [master]
    192.168.1.10
    [node]
    192.168.1.[11:13]
    [kube-cluster:children]
    master
    node
    1. Edit the groups_vars/all.yml file to customize your configuration. The following is an example of how to do this:
    kube_version: v1.14.0
    token: b0f7b8.8d1767876297d85c
    init_opts: ""
    kubeadm_opts: ""
    service_cidr: "10.96.0.0/12"
    pod_network_cidr: "10.244.0.0/16"
    calico_etcd_service: "10.96.232.136"
    network: calico
    network_interface: ""
    enable_dashboard: yes
    insecure_registries: []
    systemd_dir: /lib/systemd/system
    system_env_dir: /etc/sysconfig
    network_dir: /etc/kubernetes/network
    kubeadmin_config: /etc/kubernetes/admin.conf
    kube_addon_dir: /etc/kubernetes/addon
    1. Run the site.yaml playbook to create your cluster:
    $ ansible-playbook site.yaml

    Your cluster will be deployed based on your configuration.

    Connecting to the Kubernetes cluster

    To get access to your Kubernetes cluster, you need to follow these steps:

    1. Copy the configuration file from the master1 node:
    $ scp root@master:/etc/kubernetes/admin.conf ~/.kube/config
    1. Now, use kubectl to manage your cluster.

    See also

    lock icon
    The rest of the page is locked
    Previous PageNext Page
    You have been reading a chapter from
    Kubernetes - A Complete DevOps Cookbook
    Published in: Mar 2020Publisher: PacktISBN-13: 9781838828042

    Author (1)

    author image
    Murat Karslioglu

    Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
    Read more about Murat Karslioglu