Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# IaaSWeek - Ansible
# IaaSWeek - Ansible - K8S on Proxmox

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications — automate in a language that approaches plain English, using SSH, with no agents to install on remote systems. ([Fonte](https://www.ansible.com/))

- [Documentação](https://docs.ansible.com/ansible/latest/index.html)
- [Github](https://github.com/ansible/ansible)

- Clona as VMs no Proxmox
- Configura o CloudInit
-
5 changes: 5 additions & 0 deletions install_k8s/extras.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- hosts: k8s_master
become: yes
user: mmagalha
roles:
- { role: install-extra, tags: ["intall_extra"]}
21 changes: 16 additions & 5 deletions install_k8s/hosts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
[k8s-master]
[pve]
pve01

[k8s]
172.32.0.221
172.32.0.22[2:4]

[k8s-workers]
[k8s_master]
172.32.0.221

[k8s-workers:vars]
K8S_MASTER_NODE_IP=
K8S_API_SECURE_PORT=6443
[k8s_workers]
172.32.0.22[2:4]

[k8s_workers:vars]
K8S_MASTER_NODE_IP=172.32.0.221
K8S_API_SECURE_PORT=6443

[all:vars]
ansible_python_interpreter=/usr/bin/python3
27 changes: 19 additions & 8 deletions install_k8s/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
- hosts: all
- hosts: pve
user: root
gather_facts: no
pre_tasks:
- name: 'atualizando repo'
raw: 'apt-get update'
- name: 'instalando o python'
raw: 'apt-get install -y python3 python3-proxmoxer'
roles:
- { role: install-vms, tags: ["install_pve_vms"]}

- hosts: k8s
become: yes
user: ubuntu
user: mmagalha
gather_facts: no
pre_tasks:
- name: 'atualizando repo'
raw: 'apt-get update'
- name: 'instalando o python'
raw: 'apt-get install -y python'
raw: 'apt-get install -y python3'
roles:
- { role: install-k8s, tags: ["install_k8s_role"]}

- hosts: k8s-master
- hosts: k8s_master
become: yes
user: ubuntu
user: mmagalha
roles:
- { role: create-cluster, tags: ["create_cluster_role"]}

- hosts: k8s-workers
- hosts: k8s_workers
become: yes
user: ubuntu
user: mmagalha
roles:
- { role: join-workers, tags: ["join_workers_role"]}
- { role: join-workers, tags: ["join_workers_role"]}
8 changes: 8 additions & 0 deletions install_k8s/roles/create-cluster/files/docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
11 changes: 8 additions & 3 deletions install_k8s/roles/create-cluster/tasks/init-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@
command:
kubeadm reset --force
register: kubeadmin_init

- name: Initialize Kubernetes master with kubeadm init.
command:
kubeadm init
register: kubeadmin_init

- name: Ensure .kube directory exists.
file:
path: ~/.kube
state: directory

- name: Symlink the kubectl admin.conf to ~/.kube/conf.
file:
src: /etc/kubernetes/admin.conf
dest: ~/.kube/config
state: link
- name: Configure weavenet networking.
shell: kubectl apply -f {{ default_kubernetes_cni_weavenet_manifestUrl }}
register: weavenet_result

- name: "Cluster token"
shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
register: K8S_TOKEN

- name: "CA Hash"
shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
register: K8S_MASTER_CA_HASH

- name: "Add K8S Token and Hash to dummy host"
add_host:
name: "K8S_TOKEN_HOLDER"
token: "{{ K8S_TOKEN.stdout }}"
hash: "{{ K8S_MASTER_CA_HASH.stdout }}"

- name:
debug:
msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"

- name:
debug:
msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
3 changes: 1 addition & 2 deletions install_k8s/roles/create-cluster/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
# vars file for create-cluster
default_kubernetes_cni_weavenet_manifestUrl: "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
# vars file for create-cluster
29 changes: 29 additions & 0 deletions install_k8s/roles/install-extra/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
38 changes: 38 additions & 0 deletions install_k8s/roles/install-extra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions install_k8s/roles/install-extra/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for install-extra
23 changes: 23 additions & 0 deletions install_k8s/roles/install-extra/files/cert_manager_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Namespace
metadata:
name: cert-manager-test
---
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: test-selfsigned
namespace: cert-manager-test
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
name: selfsigned-cert
namespace: cert-manager-test
spec:
commonName: example.com
secretName: selfsigned-cert-tls
issuerRef:
name: test-selfsigned
12 changes: 12 additions & 0 deletions install_k8s/roles/install-extra/files/metallb_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.32.0.230-172.32.0.235
2 changes: 2 additions & 0 deletions install_k8s/roles/install-extra/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for install-extra
53 changes: 53 additions & 0 deletions install_k8s/roles/install-extra/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

3 changes: 3 additions & 0 deletions install_k8s/roles/install-extra/tasks/cni.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Configure weavenet networking.
shell: kubectl apply -f {{ default_kubernetes_cni_weavenet_manifestUrl }}
register: weavenet_result
4 changes: 4 additions & 0 deletions install_k8s/roles/install-extra/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# tasks file for install-extra
- include: cni.yml
- include: metallb.yml
18 changes: 18 additions & 0 deletions install_k8s/roles/install-extra/tasks/metallb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- name: Copy configure MetalLB
copy:
src: roles/install-extra/files/metallb_config.yaml
dest: /opt/metallb_config.yaml
owner: root
group: root
backup: yes
register: metallb_install

- name: Install MetalLB.
shell: kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
register: metallb_install

- name: Install MetalLB config.
shell: kubectl apply -n metallb-system-f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
register: metallb_install


2 changes: 2 additions & 0 deletions install_k8s/roles/install-extra/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions install_k8s/roles/install-extra/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- install-extra
3 changes: 3 additions & 0 deletions install_k8s/roles/install-extra/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# vars file for install-extra
default_kubernetes_cni_weavenet_manifestUrl: "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Loading