Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Kubernetes - A Complete DevOps Cookbook

You're reading from  Kubernetes - A Complete DevOps Cookbook

Product type Book
Published in Mar 2020
Publisher Packt
ISBN-13 9781838828042
Pages 584 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Murat Karslioglu Murat Karslioglu
Profile icon Murat Karslioglu

Table of Contents (12) Chapters

Preface 1. Building Production-Ready Kubernetes Clusters 2. Operating Applications on Kubernetes 3. Building CI/CD Pipelines 4. Automating Tests in DevOps 5. Preparing for Stateful Workloads 6. Disaster Recovery and Backup 7. Scaling and Upgrading Applications 8. Observability and Monitoring on Kubernetes 9. Securing Applications and Clusters 10. Logging with Kubernetes 11. Other Books You May Enjoy

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 chapter is locked
    Register for a free Packt account to unlock a world of extra content!
    A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
    Unlock this book and the full library FREE for 7 days
    Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
    Renews at $15.99/month. Cancel anytime}