Last active
July 10, 2018 03:07
-
-
Save richardsonlima/0f505e43a3079061d15677e4cdba5bbd to your computer and use it in GitHub Desktop.
digitalocean-kubernetes-1-10-cluster-using-kubeadm-on-ubuntu-16-04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew upgrade ansible | |
mkdir -p /Users/richardsonlima/k8s-digitalocean-ansible/kube-cluster | |
ssh-add ~/.ssh/id_rsa # avoiding ssh key phrase dialog | |
ansible-playbook -i hosts ~/k8s-digitalocean-ansible/kube-cluster/initial.yml | |
ansible-playbook -i hosts ~/k8s-digitalocean-ansible/kube-cluster/kube-dependencies.yml | |
ansible-playbook -i hosts ~/k8s-digitalocean-ansible/kube-cluster/master.yml | |
ansible-playbook -i hosts ~/k8s-digitalocean-ansible/kube-cluster/workers.yml | |
kubectl get nodes | |
kubectl get po --all-namespaces | |
# on master | |
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml --namespace=kube-system | |
READMORE: https://github.com/hobby-kube/guide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[masters] | |
k8s-master-01 ansible_host=138.68.105.215 ansible_user=root | |
[workers] | |
k8s-worker-01 ansible_host=207.154.253.20 ansible_user=root | |
k8s-worker-02 ansible_host=165.227.166.1 ansible_user=root | |
[all:vars] | |
ansible_python_interpreter=/usr/bin/python3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
become: yes | |
tasks: | |
- name: create the 'richardson' user | |
user: name=richardson append=yes state=present createhome=yes shell=/bin/bash | |
- name: allow 'richardson' to have passwordless sudo | |
lineinfile: | |
dest: /etc/sudoers | |
line: 'richardson ALL=(ALL) NOPASSWD: ALL' | |
validate: 'visudo -cf %s' | |
- name: set up authorized keys for the richardson user | |
authorized_key: user=richardson key="{{item}}" | |
with_file: | |
- ~/.ssh/id_rsa.pub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
become: yes | |
tasks: | |
- name: install Docker | |
apt: | |
name: docker.io | |
state: present | |
update_cache: true | |
- name: install APT Transport HTTPS | |
apt: | |
name: apt-transport-https | |
state: present | |
- name: add Kubernetes apt-key | |
apt_key: | |
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg | |
state: present | |
- name: add Kubernetes' APT repository | |
apt_repository: | |
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main | |
state: present | |
filename: 'kubernetes' | |
- name: install kubelet | |
apt: | |
name: kubelet | |
state: present | |
update_cache: true | |
- name: install kubeadm | |
apt: | |
name: kubeadm | |
state: present | |
- hosts: master | |
become: yes | |
tasks: | |
- name: install kubectl | |
apt: | |
name: kubectl | |
state: present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: masters | |
become: yes | |
tasks: | |
- name: initialize the cluster | |
shell: kubeadm init --pod-network-cidr=10.244.0.0/16 >> cluster_initialized.txt | |
args: | |
chdir: $HOME | |
creates: cluster_initialized.txt | |
- name: create .kube directory | |
become: yes | |
become_user: richardson | |
file: | |
path: $HOME/.kube | |
state: directory | |
mode: 0755 | |
- name: copy admin.conf to user's kube config | |
copy: | |
src: /etc/kubernetes/admin.conf | |
dest: /home/richardson/.kube/config | |
remote_src: yes | |
owner: richardson | |
- name: install Pod network | |
become: yes | |
become_user: richardson | |
shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml >> pod_network_setup.txt | |
args: | |
chdir: $HOME | |
creates: pod_network_setup.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: master | |
become: yes | |
gather_facts: false | |
tasks: | |
- name: get join command | |
shell: kubeadm token create --print-join-command | |
register: join_command_raw | |
- name: set join command | |
set_fact: | |
join_command: "{{ join_command_raw.stdout_lines[0] }}" | |
- hosts: workers | |
become: yes | |
tasks: | |
- name: join cluster | |
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html | |
# shell: "{{ hostvars['master'].join_command }} >> node_joined.txt" | |
shell: "{{ groups['master']|map('extract', hostvars, 'join_command') }} >> node_joined.txt" | |
args: | |
chdir: $HOME | |
creates: node_joined.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment