top of page

Ansible Playbook for Setup Docker swarm and Monitoring metrics



This ansible playbook will helpful to install docker swarm cluster setup and monitoring metrics components like node-exporter and cadvisor.


Source : https://github.com/JREXANDREW/ansible-docker-metrics

Usage in Jenkins


Create a Jenkings Job for each playbook and configure the playbook.


Playbook for Install Docker Swarmm Cluster - king_install_docker.yml

Playbook for Install Metrics Components(node-exporter,cadvisor) - king_metrics.yml


We will also use Tag in Jenkinks Job parameter.


ANSIBLE_TAGS


deploy - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the deploy role


undeploy - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the undeploy role


verify - when this parameter is passed to ANSIBLE_TAGS in "Build with Parameters, this will run only the verify role



Sample playbook for install docker and its components


---
  - name: Check if Docker is installed
    command: systemctl status docker
    register: docker_check
    ignore_errors: yes

  - name: Install yum utils
    yum:
      name: yum-utils
      state: latest
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Add Docker repo
    get_url:
      url: https://download.docker.com/linux/centos/docker-ce.repo
      dest: /etc/yum.repos.d/docer-ce.repo
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Install Docker
    package:
      name: docker-ce
      state: latest
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Install Docker cli
    package:
      name: docker-ce-cli
      state: latest
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Install Docker containerd
    package:
      name: containerd.io
      state: latest
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Enable the Docker daemon in systemd
    systemd:
      name: docker
      enabled: yes
      masked: no
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Start the Docker daemon
    systemd:
      name: docker
      state: started
      masked: no
    when: docker_check.stderr.find('service could not be found') != -1

  - name: Docker Login gcr.io
    shell: docker login -u _json_key -p "$(cat /usr/src/gcr.json)" https://gcr.io 



Kubernetes Cluster - RBAC Examples

Creating Service Account Run the following command to add a new service account called king: $ kubectl create serviceaccount king serviceaccount/king created Find the name of the secret that stores t

Kubernetes - Role-based access control (RBAC)

Kubernetes RBAC The Kubernetes API provides access to sensitive data, including deployment details, persistent storage settings, and secrets. Over the years, the Kubernetes community has provided seve

Kubernetes Cheat Sheet

This page contains a list of commonly used kubectl commands and flags. Kubectl apply - Creating objects # create resource(s) kubectl apply -f ./my-manifest.yaml # create from multiple files kubectl a

Comments


bottom of page