mirror of
https://github.com/Dannecron/netology-devops.git
synced 2025-12-25 15:22:37 +03:00
homework 12.4: complete task 2
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
tf-init:
|
||||
cd ./terraform \
|
||||
&& env $(cat .env) terraform init
|
||||
tf-plan:
|
||||
cd ./terraform \
|
||||
&& env $(cat .env) terraform plan
|
||||
@@ -26,4 +26,112 @@
|
||||
> * разворачивать 5 нод: 1 мастер и 4 рабочие ноды;
|
||||
> * работать должны на минимально допустимых виртуальных машинах
|
||||
|
||||
// todo
|
||||
Для деплоя виртуальных машин в yandex.cloud написана конфигурация [terraform](./terraform/main.tf). Для запуска процесса необходимо:
|
||||
* скопировать [variables.tf.example](./terraform/variables.tf.example) в [variables.tf](./terraform/variables.tf)
|
||||
и проставить необходимые значения (для создания нового токена можно использовать команду `yc iam create-token`)
|
||||
* просмотреть шаги, которые будут сделаны
|
||||
|
||||
```shell
|
||||
terraform plan
|
||||
```
|
||||
|
||||
* применить конфигурацию
|
||||
|
||||
```shell
|
||||
terraform apply
|
||||
```
|
||||
|
||||
__Note:__ более подробно про terraform описано в домашних заданиях [5.4](/src/homework/05-virtualization/5.4) и [7.x](/src/homework/07-terraform).
|
||||
|
||||
После выполнения в блоке `outputs` будут выведены ip-адреса созданных машин:
|
||||
|
||||
```text
|
||||
Outputs:
|
||||
|
||||
control_ips = {
|
||||
"external" = "62.84.124.154"
|
||||
"internal" = "192.168.10.12"
|
||||
}
|
||||
node_ips = {
|
||||
"external" = [
|
||||
"62.84.124.232",
|
||||
"51.250.81.132",
|
||||
"84.201.130.174",
|
||||
"62.84.127.45",
|
||||
]
|
||||
"internal" = [
|
||||
"192.168.10.3",
|
||||
"192.168.10.10",
|
||||
"192.168.10.18",
|
||||
"192.168.10.15",
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
В конфигурацию [kubespray](./kubespray/inventory.example.ini) нужно поставить значения:
|
||||
|
||||
* в `control ansible_host` значение `control_ips.external`
|
||||
* в значения нод `ansibe_host` значения из `node_ips.external`
|
||||
|
||||
Следующим шагом будет непосредственный запуск `kubespray` (из корневой директории репозитория):
|
||||
|
||||
```shell
|
||||
ansible-playbook -u ubuntu -i inventory/mycluster/inventory.ini cluster.yml -b -v
|
||||
```
|
||||
|
||||
После успешной установки необходимо подключиться по ssh к ноде `control` и настроить `kubectl`:
|
||||
|
||||
```shell
|
||||
ssh ubuntu@62.84.124.154
|
||||
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
|
||||
sudo chown ubuntu:ubuntu ~/.kube/config
|
||||
```
|
||||
|
||||
После данных действий через `kubectl` возможно выполнять команды в созданном кластере.
|
||||
|
||||
```shell
|
||||
kubectl get namespaces
|
||||
```
|
||||
|
||||
```text
|
||||
NAME STATUS AGE
|
||||
default Active 10m
|
||||
kube-node-lease Active 10m
|
||||
kube-public Active 10m
|
||||
kube-system Active 10m
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl get pods --namespace=kube-system
|
||||
```
|
||||
|
||||
```text
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
calico-node-9g626 1/1 Running 0 10m
|
||||
calico-node-9v8h5 1/1 Running 0 10m
|
||||
calico-node-fnlxc 1/1 Running 0 10m
|
||||
calico-node-pwxmx 1/1 Running 0 10m
|
||||
calico-node-vfzpk 1/1 Running 0 10m
|
||||
<...>
|
||||
```
|
||||
|
||||
А так же можно развернуть новый деплоймент (например, [hello_node_deployment.yml](/src/homework/12-kubernetes/12.2/config/hello_node_deployment.yml) из домашнего задания 12.2)
|
||||
|
||||
```shell
|
||||
kubectl apply hello_node_deployment.yml
|
||||
kubectl get deployments
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
```text
|
||||
deployment.apps/hello-node-deployment created
|
||||
|
||||
NAME READY UP-TO-DATE AVAILABLE AGE
|
||||
hello-node-deployment 4/4 4 4 14s
|
||||
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
hello-node-deployment-7484fdb5bb-8fpf7 1/1 Running 0 16s
|
||||
hello-node-deployment-7484fdb5bb-mmzr5 1/1 Running 0 16s
|
||||
hello-node-deployment-7484fdb5bb-tvd4v 1/1 Running 0 16s
|
||||
hello-node-deployment-7484fdb5bb-wbf5z 1/1 Running 0 16s
|
||||
```
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
YC_TOKEN=OAuthToken
|
||||
YC_CLOUD_ID=cloudId
|
||||
YC_FOLDER_ID=folderId
|
||||
YC_ZONE=ru-central1-a
|
||||
@@ -1,5 +1,3 @@
|
||||
.env
|
||||
|
||||
# Local .terraform directories
|
||||
**/.terraform/*
|
||||
|
||||
@@ -35,3 +33,5 @@ override.tf.json
|
||||
# Ignore CLI configuration files
|
||||
.terraformrc
|
||||
terraform.rc
|
||||
|
||||
variables.tf
|
||||
|
||||
@@ -8,9 +8,9 @@ terraform {
|
||||
}
|
||||
|
||||
provider "yandex" {
|
||||
token = "auth_token_here"
|
||||
cloud_id = "cloud_id_here"
|
||||
folder_id = "folder_id_here"
|
||||
token = var.yandex_cloud_token
|
||||
cloud_id = var.yandex_cloud_id
|
||||
folder_id = var.yandex_folder_id
|
||||
zone = "ru-central1-a"
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ resource "yandex_vpc_subnet" "subnet-1" {
|
||||
}
|
||||
|
||||
resource "yandex_compute_instance" "k8s-control" {
|
||||
name = "test-vm-1"
|
||||
name = "control"
|
||||
|
||||
resources {
|
||||
cores = 2
|
||||
@@ -35,7 +35,8 @@ resource "yandex_compute_instance" "k8s-control" {
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image_id = "fd81hgrcv6lsnkremf32" # ubuntu-20-04-lts-v20210908
|
||||
image_id = "fd8kdq6d0p8sij7h5qe3" # ubuntu-20-04-lts-v20220822
|
||||
size = "20"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,13 +56,14 @@ resource "yandex_compute_instance" "k8s-node" {
|
||||
name = each.key
|
||||
|
||||
resources {
|
||||
cores = 1
|
||||
memory = 1
|
||||
cores = 2
|
||||
memory = 2
|
||||
}
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image_id = "fd81hgrcv6lsnkremf32" # ubuntu-20-04-lts-v20210908
|
||||
image_id = "fd8kdq6d0p8sij7h5qe3" # ubuntu-20-04-lts-v20220822
|
||||
size = "20"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +79,14 @@ resource "yandex_compute_instance" "k8s-node" {
|
||||
|
||||
output "control_ips" {
|
||||
value = {
|
||||
external = yandex_compute_instance.k8s-control.network_interface.0.ip_address
|
||||
internal = yandex_compute_instance.k8s-control.network_interface.0.nat_ip_address
|
||||
internal = yandex_compute_instance.k8s-control.network_interface.0.ip_address
|
||||
external = yandex_compute_instance.k8s-control.network_interface.0.nat_ip_address
|
||||
}
|
||||
}
|
||||
|
||||
output "node_ips" {
|
||||
value = {
|
||||
external = values(yandex_compute_instance.k8s-node)[*].network_interface.0.ip_address
|
||||
internal = values(yandex_compute_instance.k8s-node)[*].network_interface.0.nat_ip_address
|
||||
internal = values(yandex_compute_instance.k8s-node)[*].network_interface.0.ip_address
|
||||
external = values(yandex_compute_instance.k8s-node)[*].network_interface.0.nat_ip_address
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# Заменить на ID своего облака
|
||||
# https://console.cloud.yandex.ru/cloud?section=overview
|
||||
variable "yandex_cloud_id" {
|
||||
default = "b1gu1gt5nqi6lqgu3t7s"
|
||||
}
|
||||
|
||||
# Заменить на Folder своего облака
|
||||
# https://console.cloud.yandex.ru/cloud?section=overview
|
||||
variable "yandex_folder_id" {
|
||||
default = "b1gaec42k169jqpo02f7"
|
||||
}
|
||||
|
||||
# OAuth токен, используемый утилитой yc. Применялся на этапе с packer.
|
||||
variable "yandex_cloud_token" {
|
||||
default = ""
|
||||
}
|
||||
Reference in New Issue
Block a user