Skip to content

VictorGil-Ops/Kubernetes_LAB

Repository files navigation

Deployment Kubernetes cluster with Ansible

this repo based in a itwonderland lab, thanks for it https://www.itwonderlab.com

  • Repository contains a playbook for kubernetes cluster easy installation based in Centos 8.

  • You can prepare virtual machines with a Vagrant.

Minimun requisites for node

node cpu memory
master 2vcore 2048mb
worker 1vcore 2048mb

Preparare Ansible Control Node

Install requisite - Ansible and ansible.posix

 ansible-galaxy collection install ansible.posix

Image

  1. Create ansible user
 sudo adduser ansible
 sudo passwd ansible
  1. Generate ssh key, path "~/.ssh/id_rsa.pub"
 su - ansible
 mkdir .ssh && cd .ssh
 ssh-keygen -t rsa
 cat id.rsa.pub ## paste inside ssh_prepare_node.sh << PASTE PUBLIC_KEY
  1. Copy the public key in prepare_nodes\prepare_nodes.sh show it for more info.

  2. Execute the script prepare_nodes.sh on kubernetes for each one k8s node.

This script create a ansible user and add the ssh key inside .ssh/authorized_keys.

Ansible playbook

  1. Check and modify the file inventory and add your ip nodes

file: inventory

[master]
master-node ansible_host=192.168.205.212

[workers]
worker-node1 ansible_host=192.168.205.211
worker-node2 ansible_host=192.168.205.212
  1. Check a defaut vars

file: edit.vars.yml

master_admin_user: "ansible"
master_admin_group: "ansible"

master_apiserver_advertise_address: "192.168.205.210"
master_pod_network_cidr: "192.168.112.0/20"

master_node_name: "k8s-m"
node_node_name: "k8s-n"
cluster_name: "k8s-cluster"

# Check the last version https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
dashboard_version: "v2.5.0"
  1. How run a playbook

Mark or desmark role

---
- import_playbook: roles/deploy-k8s-nodes.yml
#- import_playbook: roles/deploy-dashboard.yml

Run

 ansible-playbook run.me.yml -v

Copy KUBECONFIG to local:

scp ansible@master-node:/home/ansible/.kube/config ~/.kube/config

Access to dashboard:

https://master-node:30002/#/login

You find the token inside roles/k8s-cluster-dash_token-join-command.

Add ROLES label to workers nodes:

 kubectl label node worker-node1 node-role.kubernetes.io/worker=worker
 kubectl label node worker-node2 node-role.kubernetes.io/worker=worker

MANAGE CLUSTERS HELP

Roadmap TODO

  • ✅ deploy dashboard
  • ☐ enable and configure firewall
  • ☐ istio deployment

About

Create a k8s lab

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages