mirror of
https://github.com/Dannecron/netology-devops-gw-infra.git
synced 2025-12-25 15:22:36 +03:00
[stage-2] create kubectl_init ansible-playbook
fix cluster.tf, update readme
This commit is contained in:
1
ansible/kubectl_init/.gitignore
vendored
Normal file
1
ansible/kubectl_init/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/inventory
|
||||||
2
ansible/kubectl_init/group_vars/all/all.yml
Normal file
2
ansible/kubectl_init/group_vars/all/all.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
ansible_user: ubuntu
|
||||||
23
kubectl_init.yml
Normal file
23
kubectl_init.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
- name: Get kubectl configuration from control-node
|
||||||
|
hosts: control
|
||||||
|
tasks:
|
||||||
|
- name: Kubectl - get internal k8s config
|
||||||
|
become: yes
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
src: /etc/kubernetes/admin.conf
|
||||||
|
register: k8s_internal_config
|
||||||
|
- name: Kubectl - get certificate values from internal k8s config
|
||||||
|
set_fact:
|
||||||
|
k8s_certificate_auth_data={{ (k8s_internal_config['content']|b64decode|from_yaml).clusters[0].cluster['certificate-authority-data'] }}
|
||||||
|
k8s_user_client_cert_data={{ (k8s_internal_config['content']|b64decode|from_yaml).users[0].user['client-certificate-data'] }}
|
||||||
|
k8s_user_client_key_data={{ (k8s_internal_config['content']|b64decode|from_yaml).users[0].user['client-key-data'] }}
|
||||||
|
- name: Kubectl - create kubectl config from template
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: "{{ playbook_dir }}/templates/kubectl/conf.j2"
|
||||||
|
dest: "~/.kube/config"
|
||||||
|
- name: Kubectl - check connection
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: kubectl get pods -A
|
||||||
@@ -27,3 +27,7 @@
|
|||||||
ansible.builtin.pip:
|
ansible.builtin.pip:
|
||||||
chdir: "{{ playbook_dir }}/vendor/kubespray"
|
chdir: "{{ playbook_dir }}/vendor/kubespray"
|
||||||
requirements: requirements.txt
|
requirements: requirements.txt
|
||||||
|
- name: Kubectl - initialize inventory
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: "{{ playbook_dir }}/templates/kubectl/inventory.j2"
|
||||||
|
dest: "{{ playbook_dir }}/ansible/kubectl_init/inventory"
|
||||||
|
|||||||
16
readme.md
16
readme.md
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
|
|
||||||
|
Необходимо последовательно выполнить все шаги, описанные ниже. Каждый ansible-playbook описывает один шаг.
|
||||||
|
|
||||||
### Инициализация конфигурации terraform
|
### Инициализация конфигурации terraform
|
||||||
|
|
||||||
* [ansible playbook `terraform_init.yml`](/terraform_init.yml)
|
* [ansible playbook `terraform_init.yml`](/terraform_init.yml)
|
||||||
@@ -40,9 +42,6 @@ terraform apply
|
|||||||
ansible-playbook -i ansible/kubespray_init kubespray_init.yml
|
ansible-playbook -i ansible/kubespray_init kubespray_init.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
__NOTES__:
|
|
||||||
* на данном этапе необходимо, чтобы инфрастуктура уже была задеплоена через `terraform`.
|
|
||||||
|
|
||||||
### Запуск kubespray: установка кластера kubernetes
|
### Запуск kubespray: установка кластера kubernetes
|
||||||
|
|
||||||
* [ansible playbook `vendor/kubespray/cluster.yml`](/vendor/kubespray/cluster.yml) (будет создан на этапе конфигурации kubespray)
|
* [ansible playbook `vendor/kubespray/cluster.yml`](/vendor/kubespray/cluster.yml) (будет создан на этапе конфигурации kubespray)
|
||||||
@@ -53,3 +52,14 @@ __NOTES__:
|
|||||||
```shell
|
```shell
|
||||||
ansible-playbook -i ansible/kubespray/inventory.ini vendor/kubespray/cluster.yml
|
ansible-playbook -i ansible/kubespray/inventory.ini vendor/kubespray/cluster.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Инициализация конфигурации kubectl
|
||||||
|
|
||||||
|
* [ansible playbook `kubectl_init.yml`](/kubectl_init.yml)
|
||||||
|
* [ansible inventory](/ansible/kubectl_init) (сам файл `inventory` будет создан на этапе конфигурации kubespray)
|
||||||
|
|
||||||
|
Запуск:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
ansible-playbook -i ansible/kubectl_init kubectl_init.yml
|
||||||
|
```
|
||||||
|
|||||||
20
templates/kubectl/conf.j2
Normal file
20
templates/kubectl/conf.j2
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
clusters:
|
||||||
|
- cluster:
|
||||||
|
certificate-authority-data: {{ k8s_certificate_auth_data }}
|
||||||
|
server: https://{{ hostvars['control'].ansible_host }}:6443
|
||||||
|
name: cluster.local
|
||||||
|
contexts:
|
||||||
|
- context:
|
||||||
|
cluster: cluster.local
|
||||||
|
user: kubernetes-admin
|
||||||
|
name: kubernetes-admin@cluster.local
|
||||||
|
current-context: kubernetes-admin@cluster.local
|
||||||
|
kind: Config
|
||||||
|
preferences: {}
|
||||||
|
users:
|
||||||
|
- name: kubernetes-admin
|
||||||
|
user:
|
||||||
|
client-certificate-data: {{ k8s_user_client_cert_data }}
|
||||||
|
client-key-data: {{ k8s_user_client_key_data }}
|
||||||
2
templates/kubectl/inventory.j2
Normal file
2
templates/kubectl/inventory.j2
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[all]
|
||||||
|
control ansible_host={{ kube_control_node_host }}
|
||||||
@@ -21,7 +21,7 @@ resource "yandex_compute_instance" "k8s-cluster" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
network_interface {
|
network_interface {
|
||||||
subnet_id = random_shuffle.netology-gw-subnet-random.result
|
subnet_id = random_shuffle.netology-gw-subnet-random.result[0]
|
||||||
nat = true
|
nat = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user