This repository was archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
added k8s ansible deployment process #15
Open
yanmo96
wants to merge
5
commits into
futurewei-cloud:master
Choose a base branch
from
yanmo96:ansible_k8s
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
scripts/ansible-playbook/k8s_deploy_fresh_machine/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| # Install k8s with Ansible use root user on ubuntu 18.04 | ||
|
|
||
|
|
||
| ### Install python3 and etc... | ||
| `apt update` | ||
|
|
||
| `sudo apt install python3-dev python3-venv libffi-dev gcc libssl-dev git` | ||
|
|
||
| ### Install ansible with python3 on one machine | ||
| `pip install 'ansible<=2.11'` | ||
|
|
||
| ### Reference the bellow link, but need to make minor adjustments | ||
| https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-ubuntu-18-04 | ||
|
|
||
| ___ | ||
|
|
||
| ## Step 1: prepare ansible and setup inventory (list of machines) | ||
|
|
||
| ``` | ||
| mkdir ~/kube-cluster | ||
| cd ~/kube-cluster | ||
| vim ~/kube-cluster/hosts | ||
| ``` | ||
|
|
||
| ``` | ||
| [masters] | ||
| master ansible_host=master_ip ansible_user=root | ||
|
|
||
| [workers] | ||
| worker1 ansible_host=worker_1_ip ansible_user=root | ||
| worker2 ansible_host=worker_2_ip ansible_user=root | ||
|
|
||
| [all:vars] | ||
| ansible_python_interpreter=/usr/bin/python3 | ||
| ``` | ||
|
|
||
| ___ | ||
|
|
||
| ## Step 2: Install K8s dependencies (include Docker) | ||
|
|
||
| `vim ~/kube-cluster/kube-dependencies.yml` | ||
|
|
||
| ``` | ||
| - 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=1.19.4-00 | ||
| state: present | ||
| update_cache: true | ||
|
|
||
| - name: install kubeadm | ||
| apt: | ||
| name: kubeadm=1.19.4-00 | ||
| state: present | ||
|
|
||
| - hosts: master | ||
| become: yes | ||
| tasks: | ||
| - name: install kubectl | ||
| apt: | ||
| name: kubectl=1.19.4-00 | ||
| state: present | ||
| force: yes | ||
| ``` | ||
|
|
||
| ### Run the above ansilbe playbook, with the host folder setuped earlier | ||
| `ansible-playbook -i hosts ~/kube-cluster/kube-dependencies.yml` | ||
|
|
||
| ___ | ||
|
|
||
| ## Step 3: Set up Master Node | ||
| `vim ~/kube-cluster/master.yml` | ||
|
|
||
| ``` | ||
| - hosts: master | ||
| 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: install Pod network, flannel | ||
| environment: | ||
| KUBECONFIG: /etc/kubernetes/admin.conf | ||
| become: yes | ||
| shell: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml >> pod_network_setup.txt | ||
| args: | ||
| chdir: $HOME | ||
| creates: pod_network_setup.txt | ||
| ``` | ||
|
|
||
| ### Run the above ansilbe playbook, with the host folder setuped earlier | ||
| `ansible-playbook -i hosts ~/kube-cluster/master.yml` | ||
|
|
||
| ### To check the installation of k8s master node | ||
|
|
||
| ``` | ||
| kubectl get nodes | ||
| kubectl get pods -A | ||
| ``` | ||
|
|
||
| ___ | ||
|
|
||
| ## Step 4: Setup Worker Nodes | ||
|
|
||
| `vim ~/kube-cluster/workers.yml` | ||
|
|
||
| ``` | ||
| - hosts: master | ||
| become: yes | ||
| gather_facts: false | ||
| tasks: | ||
| - name: get join command | ||
| environment: | ||
| KUBECONFIG: /etc/kubernetes/admin.conf | ||
| 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 | ||
| shell: "{{ hostvars['master'].join_command }} >> node_joined.txt" | ||
| args: | ||
| chdir: $HOME | ||
| creates: node_joined.txt | ||
| ``` | ||
|
|
||
|
|
||
| ### Run the above ansilbe playbook, with the host folder setuped earlier | ||
| `ansible-playbook -i hosts ~/kube-cluster/workers.yml` | ||
|
|
||
| ### On k8s control node export k8s admin conf. | ||
| ### Put following line in /root/.profile | ||
|
|
||
| `export KUBECONFIG=/etc/kubernetes/admin.conf` | ||
|
|
||
| ### Then exit and log back in again | ||
|
|
||
| ### To verify the Cluster | ||
| `kubectl get nodes -o wide` | ||
9 changes: 9 additions & 0 deletions
9
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/hosts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [masters] | ||
| master ansible_host=master_ip ansible_user=root | ||
|
|
||
| [workers] | ||
| worker1 ansible_host=worker_1_ip ansible_user=root | ||
| worker2 ansible_host=worker_2_ip ansible_user=root | ||
|
|
||
| [all:vars] | ||
| ansible_python_interpreter=/usr/bin/python3 |
44 changes: 44 additions & 0 deletions
44
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/kube-dependencies.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| - 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=1.21.4-00 | ||
| state: present | ||
| update_cache: true | ||
|
|
||
| - name: install kubeadm | ||
| apt: | ||
| name: kubeadm=1.21.4-00 | ||
| state: present | ||
|
|
||
| - hosts: master | ||
| become: yes | ||
| tasks: | ||
| - name: install kubectl | ||
| apt: | ||
| name: kubectl=1.21.4-00 | ||
| state: present | ||
| force: yes |
17 changes: 17 additions & 0 deletions
17
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/master.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| - hosts: master | ||
| 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: install Pod network, flannel | ||
| environment: | ||
| KUBECONFIG: /etc/kubernetes/admin.conf | ||
| become: yes | ||
| shell: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml >> pod_network_setup.txt | ||
| args: | ||
| chdir: $HOME | ||
| creates: pod_network_setup.txt |
14 changes: 14 additions & 0 deletions
14
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/prepare_machine.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| - hosts: workers | ||
| become: yes | ||
| tasks: | ||
| - name: install pip | ||
| apt: | ||
| name: python3-pip | ||
| state: present | ||
| - name: Install Docker python package | ||
| pip: | ||
| name: docker | ||
| - name: Install ovs | ||
| apt: | ||
| name: openvswitch-switch=2.9.8-0ubuntu0.18.04.2 | ||
| state: present |
63 changes: 63 additions & 0 deletions
63
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/pull_image.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| - hosts: workers | ||
| become: yes | ||
| tasks: | ||
| - name: pull osrg/ryu | ||
| docker_image: | ||
| name: osrg/ryu | ||
| - name: pull phudtran/aca | ||
| docker_image: | ||
| name: phudtran/aca | ||
| - name: pull yanmo96/ovs_only | ||
| docker_image: | ||
| name: yanmo96/ovs_only | ||
| - name: pull yanmo96/aca_build_standard:v2 | ||
| docker_image: | ||
| name: yanmo96/aca_build_standard:v2 | ||
| - name: pull yanmo96/network_config_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/network_config_manager:v1.0 | ||
| - name: pull yanmo96/vpc_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/vpc_manager:v1.0 | ||
| - name: pull yanmo96/subnet_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/subnet_manager:v1.0 | ||
| - name: pull yanmo96/security_group_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/security_group_manager:v1.0 | ||
| - name: pull yanmo96/route_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/route_manager:v1.0 | ||
| - name: pull yanmo96/quota_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/quota_manager:v1.0 | ||
| - name: pull yanmo96/private_ip_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/private_ip_manager:v1.0 | ||
| - name: pull yanmo96/port_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/port_manager:v1.0 | ||
| - name: pull yanmo96/node_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/node_manager:v1.0 | ||
| - name: pull yanmo96/network_acl_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/network_acl_manager:v1.0 | ||
| - name: pull yanmo96/mac_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/mac_manager:v1.0 | ||
| - name: pull yanmo96/gateway_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/gateway_manager:v1.0 | ||
| - name: pull yanmo96/elastic_ip_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/elastic_ip_manager:v1.0 | ||
| - name: pull yanmo96/data_plane_manager:v1.0 | ||
| docker_image: | ||
| name: yanmo96/data_plane_manager:v1.0 | ||
| - name: pull yanmo96/api_gateway:v1.0 | ||
| docker_image: | ||
| name: yanmo96/api_gateway:v1.0 | ||
| - name: pull yanmo96/ignite_alcor:lib8 | ||
| docker_image: | ||
| name: yanmo96/ignite_alcor:lib8 |
22 changes: 22 additions & 0 deletions
22
scripts/ansible-playbook/k8s_deploy_fresh_machine/kube-cluster/workers.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| - hosts: master | ||
| become: yes | ||
| gather_facts: false | ||
| tasks: | ||
| - name: get join command | ||
| environment: | ||
| KUBECONFIG: /etc/kubernetes/admin.conf | ||
| 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 | ||
| shell: "{{ hostvars['master'].join_command }} >> node_joined.txt" | ||
| args: | ||
| chdir: $HOME | ||
| creates: node_joined.txt |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yanmo96 Do you have instruction in the README to show user how to run your ansible script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 👍