MultiCloud Kubernetes Setup

Kubernetes Master Node AWS

- name: Initializing Kubeadm Servicessetup
command: kubeadm init — pod-network-cidr= — ignore-preflight-errors=NumCPU — ignore-preflight-errors=Mem
ignore_errors: true- name: Creating .kube directory
path: ~/.kube
state: directory
mode: 0755- name: link the admin.conf with .kube/admin file
src: /etc/kubernetes/admin.conf
dest: ~/.kube/config
state: link
mode: 0644- name: Generating a token
command: kubeadm token create — print-join-command
register: token- name: Set the kubeadm join command globally
kubernetes_join_command: >
{{ token.stdout }}
when: token.stdout is defined
delegate_to: “{{ item }}”
delegate_facts: true
with_items: “{{ groups[‘all’] }}”- name: Transfering network file
src: kube-flannel.yml
dest: /root/kube-flannel.yml- name: Creating an Overlay Network to connect worker nodes
command: kubectl apply -f /root/kube-flannel.yml
$ kubeadm init --pod-network-cidr= --control-plane-endpoint={{ control_plane_endpoint_ip }}:6443 --ignore-preflight-errors=NumCPU  --ignore-preflight-errors=MeKubernetes Slave-1 over GCP

Kubernetes Slave-1 over Azure

# This playbook create an Azure VM with public IP, and open 22 port for SSH, and add ssh public key to the VM.
# This playbook create an Azure VM with public IP
# Change variables below to customize your VM deployment- name: Create Azure VM
hosts: localhost
connection: local
resource_group: "{{ resource_group_name }}"
vm_name: testvm
location: eastus
ssh_key: "<KEY>"
- name: Create a resource group
name: "{{ resource_group }}"
location: "{{ location }}" - name: Create virtual network
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
address_prefixes: "" - name: Add subnet
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
address_prefix: ""
virtual_network: "{{ vm_name }}" - name: Create public IP address
resource_group: "{{ resource_group }}"
allocation_method: Static
name: "{{ vm_name }}" - name: Create Network Security Group that allows SSH
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 1001
direction: Inbound - name: Create virtual network interface card
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
virtual_network: "{{ vm_name }}"
subnet: "{{ vm_name }}"
public_ip_name: "{{ vm_name }}"
security_group: "{{ vm_name }}"- name: Create VM
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
vm_size: Standard_DS1_v2
admin_username: azureuser
ssh_password_enabled: false
- path: /home/azureuser/.ssh/authorized_keys
key_data: "{{ ssh_key }}"
network_interfaces: "{{ vm_name }}"
offer: CentOS
publisher: OpenLogic
sku: 7.5
version: latest

Kubernetes Slave-2 over GCP

- name: Create an instance
hosts: localhost
gather_facts: no
gcp_project: my-project
gcp_cred_kind: serviceaccount
gcp_cred_file: /home/my_account.json
zone: "us-central1-a"
region: "us-central1"tasks:
- name: create a disk
name: 'disk-instance'
size_gb: 50
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts'
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: disk
- name: create a address
name: 'address-instance'
region: "{{ region }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: address
- name: create a instance
state: present
name: test-vm
machine_type: n1-standard-1
- auto_delete: true
boot: true
source: "{{ disk }}"
- network: null # use default
- name: 'External NAT'
nat_ip: "{{ address }}"
type: 'ONE_TO_ONE_NAT'
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
register: instance- name: Wait for SSH to come up
wait_for: host={{ address.address }} port=22 delay=10 timeout=60- name: Add host to groupname
add_host: hostname={{ address.address }} groupname=new_instances

Setting up as Worker Nodes

- name: connecting to the master node  shell: >  {{ kubernetes_join_command }}




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

HackTheBox — Curling Walkthrough

Elasticsearch Tips & Tricks, Part 2: Risks of Using Dynamic Mappings

Unbeatable Tic Tac Toe

How to organise a hackathon, kind of.

How to Display the Last Updated Date of Your Posts in WordPress

HTTPServer: the CRUD test really tested me

MuseDev Is Joining Sonatype!

CSS Grid Layout

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sangeeth Sahana D

Sangeeth Sahana D

More from Medium

Build Private Cloud with OpenStack Kolla-ansible Step by Step Guide 1.0

Using “Let’s Encrypt” Certificate Authority

Simplify your IBM Cloud Pak component instance certificates management with IBM Cloud Pak…

How to setup Elasticsearch+Kibana and enable Authentication in Ubuntu 20.04