bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 19쪽 중 11쪽
e fullnode daemons required for each of THORNode's chain integrations.
# Cluster Launcher
Deploying a THORNode with Kubernetes
## **Deploy a Kubernetes cluster**
In order to deploy all the different services and provide a high availability environment to operate your node, Kubernetes is the preferred scheduling platform. Any production-grade Kubernetes cluster can be used to run and deploy a THORNode. You need your Kubernetes provider to offer external load balancers services type features. Azure, Digital Ocean, GCE, OpenStack are compatible with external load balancers.
{% hint style="info" %}
Terraform is a type of domain-specific language (DSL) used to describe code infrastructure. It is designed to make it easier to create/destroy infrastructure hosted locally or by a provider.
{% endhint %}
This Terraform deployment will deploy a Kubernetes cluster using your VPS provider credentials and EKS service. The cluster will have autoscaling capabilities, which means you don’t have to deal with how many nodes you need to deploy to run your THORNode services.
All the default configurations used in these instructions are for a production environment with enough resources to run your THORNode in good conditions.
{% hint style="warning" %}
**LINUX/MAC is the preferred method of setup.**
Windows should choose either:
1. Deploy a THORNode from a Linux VPS.
2. Use Windows Subsystem for Linux - <https://docs.microsoft.com/en-us/windows/wsl/about>
{% endhint %}
## Steps
There are three important steps to getting your node set up, deployed and churned in.
1. [Setting up Cluster](/thornodes/kubernetes/setup-aws)
2. [Deploying THORNode Services](/thornodes/deploying)
3. [Joining ("Churning In")](/thornodes/joining)
### Repository Management
Your repository can be organised as follows:
```
./thornode-ops
|./cluster-launcher
|./node-launcher
```
All of your set up commands are run in `cluster-launcher` and all of your deploying/joining/managing/leaving commands are run from `node-launcher`
### Running Two or More Nodes
{% hint style="danger" %}
To prevent a catastrophic mistake in handling multiple nodes, set them up on different machines, or use different user profiles on your machine, or in the least, use different repos:
{% endhint %}
```
./thornode-ops
|./cluster-launcher
|./node-launcher
./thornode-ops2
|./cluster-launcher
|./node-launcher
```
All of your commands can now be run separately. See [Multi Validator Cluster](https://gitlab.com/thorchain/devops/node-launcher/-/blob/master/docs/Multi-Validator-Cluster.md?ref_type=heads) docs for more information.
{% hint style="warning" %}
It is heavily advised to not set up nodes on the same provider. Deploy 1 node on Azure, 1 node on Digital Ocean etc.
{% endhint %}
# Setup - Linode
Setting up a Kubernetes Cluster with Linode (linode)
## Deploy a Kubernetes cluster in Linode using LKE service.
### Requirements
1. a Linode account
2. `linode-cli` and linode credentials configured
3. `kubectl`
{% hint style="warning" %}
**LINUX/MAC is the preferred method of setup.**
**Windows should choose either:**
1. **Deploy a THORNode from a Linux VPS.**
2. **Use Windows Subsystem for Linux -** [**https://docs.microsoft.com/en-us/windows/wsl/about**](https://docs.microsoft.com/en-us/windows/wsl/about)\*\*\*\*
{% endhint %}
### linode-cli
To install the linode-cli (Linode CLI), follow [these instructions](https://github.com/linode/linode-cli#installation).
You need to have pip (python) on your system.
```bash
pip install linode-cli --upgrade
```
Create a Linode API token for your account with read and write access from your [profile page](https://cloud.linode.com/profile/tokens). The token string is only displayed once, so save it in a safe place.
Use the API token to grant linode-cli access to your Linode account. Pass in the token string when prompted by linode-cli.
```bash
linode-cli
```
### kubectl
To install the kubectl (Kubernetes CLI), follow [these instructions](https://kubernetes.io/docs/tasks/tools/install-kubectl/) or choose a package manager based on your operating system.
MacOS:
Use the package manager [homebrew](https://formulae.brew.sh/) to install kubectl.
```bash
brew install kubernetes-cli
```
Windows:
Use the package manager [Chocolatey](https://chocolatey.org/) to install kubectl.
```bash
choco install kubernetes-cli
```
### wget
To install the wget, follow [these instructions](https://www.gnu.org/software/wget/) or choose a package manager based on your operating system.
MacOS:
Use the package manager [homebrew](https://formulae.brew.sh/) to install wget.
```bash
brew install wget
```
Windows:
Use the package manager [Chocolatey](https://chocolatey.org/) to install wget.
```bash
choco install wget
```
## Deploy Kubernetes Cluster
Use the commands below to deploy a Kubernetes cluster.
You can run the make command that automates those command for you like this:
```bash
make linode
```
Or manually run each commands:
```bash
cd linode/
terraform init
terraform plan # to see the plan
terraform apply
```
## Configure kubectl
Now that you've provisioned your Kubernetes cluster, you need to configure kubectl.
To configure authentication from the command line, use the following command, substituting the ID of your cluster.
```bash
# Store it - method #1
jq -r ".resources[].instances[].attributes.kubeconfig" linode/terraform.tfstate | base64 -D > ~/.kube/config-linode
# Store it - method #2
linode-cli lke kubeconfig-view <use_your_cluster_id> > ~/.kube/config-linode
# Merge it and set current context
KUBECONFIG=~/.kube/config:~/.kube/config-linode kubectl config view --flatten > ~/.kube/tmpcfg && mv -f ~/.kube/tmpcfg ~/.kube/config && kubectl config use-context $(kubectl config current-context --kubeconfig=~/.kube/config-linode)
# Or just view it - method #1
jq -r ".resources[].instances[].attributes.kubeconfig" linode/terraform.tfstate | base64 -D
# Or just view it - method #2
linode-cli lke kubeconfig-view <use_your_cluster_id>
```
> Note: If the above `linode-cli` command is broken you can download the file from the web [dashboar](https://cloud.linode.com/kubernetes/clusters) for the respective cluster.
This replaces the existing configuration at \~/.kube/config.
Once done, you can check your cluster is responding correctly by running the command:
```bash
kubectl version
kubectl get nodes
```
## Clean up your workspace
To destroy and remove previously created resources, you can run the command below.
```bash
make destroy-linode
```
Or run the commands manually:
```bash
cd linode/
terraform destroy
```
# Setup - Azure
Setting up a Kubernetes Cluster with Azure (AKS)
## **Deploy a Kubernetes cluster in Azure using AKS service.**
### **Requirements**
1. Azure account
2. `az` and Azure credentials configured
3. `kubectl`
{% hint style="warning" %}
**LINUX/MAC is the preferred method of setup.**
**Windows should choose either:**
1. **Deploy a THORNode from a Linux VPS.**
2. **Use Windows Subsystem for Linux -** [**https://docs.microsoft.com/en-us/windows/wsl/about**](https://docs.microsoft.com/en-us/windows/wsl/about)\*\*\*\*
{% endhint %}
## **Steps**
Firstly, clone and enter the [cluster-launcher repository](https://gitlab.com/thorchain/devops/cluster-launcher)**.** All commands in this section are to be run inside this repo.
```
git clone https://gitlab.com/thorchain/devops/cluster-launcher
cd cluster-launcher
```
Then install the [terraform CLI](https://www.terraform.io):
{% tabs %}
{% tab title="LINUX/MAC" %}
Install Terraform:
```bash
brew install terraform
```
{% endtab %}
{% endtabs %}
#### **Azure CLI**
The [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/) allows you to manage your Azure services.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install the Azure CLI.
```bash
brew install azure-cli
az login
```
{% endtab %}
{% endtabs %}
{% hint style="warning" %}
You will be asked for you Personal Access Token with read/write priveleges (retrieve from API Panel from the Azure web console.)
**API -> Tokens/Keys -> Create Token.**
Make sure you handle your secrets securely!
{% endhint %}
#### Kubernetes Control Tool
You must install and configure the Kubernetes CLI tool (**kubectl**). **\*\*To install** kubectl\*\* , follow [these instructions](https://kubernetes.io/docs/tasks/tools/install-kubectl/), or choose a package manager based on your operating system.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install **kubectl**.
```bash
brew install kubernetes-cli
```
{% endtab %}
{% endtabs %}
#### **wget && jq**
You also need **wget** and **jq**, follow [these instructions](https://www.gnu.org/software/wget/), or choose a package manager based on your operating system.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install **wget** and **jq** *Note: You most likely have these installed already.*
```bash
brew install wget
brew install jq
```
{% endtab %}
{% endtabs %}
## **Deploy Kubernetes Cluster**
Use the commands below to deploy an AKS cluster:
```bash
make azure
```
During the deploy, you will be asked to enter information about your cluster:
```bash
var.location
The location where the Managed Kubernetes Cluster should be created
Enter a value: eastus2
var.name
The base name used for all resources
Enter a value: tc-k8s
```
* Location -- `az account list-locations -o table`
* Name
* Confirm `yes`
{% hint style="info" %}
Deploying a cluster takes \~15 minutes
{% endhint %}
## CONFIGURE
Now that you've provisioned your AKS cluster, you need to configure **kubectl**. Customize the following command with your cluster name and resource group. It will get the access credentials for your cluster and automatically configure kubectl.
```bash
az aks get-credentials -a -g <resource_group> -n <cluster_name>
```
This replaces the existing configuration at \~/.kube/config.
Once done, you can check if your cluster is responding correctly by running the following commands.
```bash
kubectl version
kubectl get nodes
```
You are now ready to deploy a THORNode.
# Setup - Hetzner Bare Metal
Setting up a Kubernetes Cluster with Hetzner Dedicated Servers
{% hint style="danger" %}
This guide for Hetzner Bare Metal is WIP and not currently recommended. Proceed with caution until an update is released and this warning removed.
{% endhint %}
> Checkout the repository [source](https://github.com/delphidigital/bare-metal-cluster-manager) to manage a cluster of dedicated servers on Hetzner.
The scripts in this repository will setup and maintain one or more [kubernetes](https://kubernetes.io) clusters consisting of dedicated [Hetzner](https://www.hetzner.com) servers. Each cluster will also be provisioned to operate as a node in the [THORCHain](https://thorchain.org) network.
Executing the scripts in combination with some manual procedures will get you highly available, secure clusters with the following features on bare metal.
* [Kubespray](https://kubespray.io/) (based)
* Internal NVMe storage ([Ceph](https://ceph.io)/[Rook](https://rook.io))
* Virtual LAN (also over multiple locations) ([Calico](https://www.projectcalico.org))
* Load Balancing ([MetalLB](https://metallb.universe.tf))
## Preparations
### Servers
Acquire a couple of [servers](https://www.hetzner.com/dedicated-rootserver/matrix-ax) as the basis for a cluster (`AX41-NVME`'s are working well for instance). Visit the [admin panel](https://robot.your-server.de/server) and name the servers appropriately.
```
tc-k8s-node1
tc-k8s-node2
tc-k8s-node3
...
tc-k8s-master1
tc-k8s-master2
tc-k8s-worker1
tc-k8s-worker2
tc-k8s-worker3
...
```
Refer to the [reset procedure](#resetting-the-bare-metal-servers) to properly initialize them.
### vSwitch
Create a [vSwitch](https://robot.your-server.de/vswitch/index) and order an appropriate subnet (it may take a while to show up after the order). Give the vSwitch a name (i.e. `tc-k8s-net`) and assign this vSwitch to the servers.
Checkout the [docs](https://docs.hetzner.com/robot/dedicated-server/network/vswitch) for help.
## Usage
Clone this repository, `cd` into it and download kubespray.
```bash
git submodule init && git submodule update
```
Create a Python virtual environment or similar.
```bash
# Optional
virtualenv -p python3 venv
```
Install dependencies required by Python and Ansible Glaxy.
```bash
pip install -r requirements.python.txt
ansible-galaxy install -r requirements.ansible.yml
```
> Note: [Mitogen](https://mitogen.readthedocs.io/en/python3/ansible.html) does not work with ansible collections and the strategy must be changed (i.e. `strategy: linear`).
### Provisioning
Create a deployment environment inventory file for each cluster you want to manage.
```bash
cp hosts.example inventory/production.yml
cp hosts.example inventory/test.yml
cp hosts.example inventory/environment.yml
...
cp hosts.example inventory/production-01.yml
cp hosts.example inventory/production-02.yml
...
cp hosts.example inventory/production-helsinki.yml
cp hosts.example inventory/whatever.yml
```
Edit the inventory file with your server ip's and network information and customize everything to your needs.
```bash
# Manage a cluster
ansible-playbook cluster.init.yml -i inventory/environment.yml
ansible-playbook --become --become-user=root kubespray/cluster.yml -i inventory/environment.yml
ansible-playbook cluster.finish.yml -i inventory/environment.yml
# Run custom playbooks
ansible-playbook private-cluster.yml -i inventory/environment.yml
ansible-playbook private-test-cluster.yml -i inventory/environment.yml
ansible-playbook private-whatever-cluster.yml -i inventory/environment.yml
```
> Check [this](https://kubespray.io/) out for more playbooks on cluster management.
### THORChain
In order for the cluster to operate as a node in the THORCHain network deploy as instructed [here](https://docs.thorchain.org/thornodes/kubernetes/deploying). You can also refer to the [node-launcher repository](https://gitlab.com/thorchain/devops/node-launcher), if necessary, or the THORChain [documentation](https://docs.thorchain.org) as a whole.
## Resetting the bare metal servers
This will install and use Ubuntu 20.04 on only one of the two internal NVMe drives. The unused ones will be used for persistent storage with ceph/rook. You can check the internal drive setup with `lsblk`. Change it accordingly in the command shown above when necessary.
### Manually
Visit the [console](https://robot.your-server.de/server) and put each server of the cluster into rescue mode. Then execute the following script.
```bash
installimage -a -r no -i images/Ubuntu-2004-focal-64-minimal.tar.gz -p /:ext4:all -d nvme0n1 -f yes -t yes -n hostname
```
### Automatically
Create a pristine state by running the playbooks in sequence.
```bash
ansible-playbook server.rescue.yml -i inventory/environment.yml
ansible-playbook server.bootstrap.yml -i inventory/environment.yml
```
### Instantiation
Instantiate the servers.
```bash
ansible-playbook server.instantiate.yml -i inventory/environment.yml
```
# Setup - Google Cloud
Setting up a Kubernetes Cluster with GCP (GKE)
## **Deploy a Kubernetes cluster in GCP using GKE service.**
### **Requirements**
1. GCP account
2. `gcloud` and GCP credentials configured
3. `kubectl`
{% hint style="warning" %}
**LINUX/MAC is the preferred method of setup.**
**Windows should choose either:**
1. **Deploy a THORNode from a Linux VPS.**
2. **Use Windows Subsystem for Linux -** [**https://docs.microsoft.com/en-us/windows/wsl/about**](https://docs.microsoft.com/en-us/windows/wsl/about)\*\*\*\*
{% endhint %}
## **Steps**
Firstly, clone and enter the [cluster-launcher repository](https://gitlab.com/thorchain/devops/cluster-launcher)**.** All commands in this section are to be run inside this repo.
```
git clone https://gitlab.com/thorchain/devops/cluster-launcher
cd cluster-launcher
```
Then install the [terraform CLI](https://www.terraform.io):
{% tabs %}
{% tab title="LINUX/MAC" %}
Install Terraform:
```bash
brew install terraform
```
{% endtab %}
{% endtabs %}
#### **gcloud CLI**
The [gcloud CLI](https://cloud.google.com/sdk/docs/install) allows you to manage your GCP services.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install the GCP CLI.
```bash
brew install google-cloud-sdk
```
{% endtab %}
{% endtabs %}
After the installation perform the steps outlined below. This will authorize the SDK to access GCP using your user account credentials and add the SDK to your PATH. It requires you to login and select the project you want to work in. Then add your account to the Application Default Credentials (ADC). This will allow Terraform to access these credentials to provision resources on GCP. Finally, you need to enable the Compute Engine and Kubernetes Engine API services for your GCP project.
```bash
gcloud init
gcloud auth application-default login
gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com
```
{% hint style="warning" %}
You will be asked for you Personal Access Token with read/write priveleges (retrieve from API Panel from the GCP web console.)
**API -> Tokens/Keys -> Create Token.**
Make sure you handle your secrets securely!
{% endhint %}
#### Kubernetes Control Tool
You must install and configure the Kubernetes CLI tool (**kubectl**). **\*\*To install** kubectl\*\* , follow [these instructions](https://kubernetes.io/docs/tasks/tools/install-kubectl/), or choose a package manager based on your operating system.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install **kubectl**.
```bash
brew install kubernetes-cli
```
{% endtab %}
{% endtabs %}
#### **wget && jq**
You also need **wget** and **jq**, follow [these instructions](https://www.gnu.org/software/wget/), or choose a package manager based on your operating system.
{% tabs %}
{% tab title="LINUX/MAC" %}
Use the package manager [homebrew](https://formulae.brew.sh/) to install **wget** and **jq** *Note: You most likely have these installed already.*
```bash
brew install wget
brew install jq
```
{% endtab %}
{% endtabs %}
## **Deploy Kubernetes Cluster**
Use the commands below to deploy an GKE cluster:
```bash
make gcp
```
During the deploy, you will be asked to enter information about your cluster:
```bash
var.project_id
Project ID
Enter a value: tc-k8s-123456
var.zone
GCP zone in region
Enter a value: us-east1-d
```
* Project ID
* Zone -- `gcloud compute zones list`
* Confirm `yes`
{% hint style="info" %}
Deploying a cluster takes \~15 minutes
{% endhint %}
## CONFIGURE
Now that you've provisioned your GKE cluster, you need to configure **kubectl**. The following command will get the access credentials for your cluster and automatically configure kubectl.
```bash
(cd gcp && gcloud container clusters get-credentials $(terraform output cluster_name) --zone $(terraform output zone))
```
This replaces the existing configuration at \~/.kube/config.
Once done, you can check if your cluster is responding correctly by running the following commands.
```bash
kubectl version
kubectl get nodes
```
You are now ready to deploy a THORNode.
# Setup - HCloud
Setting up a Kubernetes Cluster with Hetzner Cloud (hcloud)
## **Deploy an umnanaged Kubernetes cluster in hcloud**
{% hint style="warning" %}
This approach is only recommended for experienced operators because the kubernetes control plane among other things needs to be managed manually.
{% endhint %}
### **Requirements**
1. hcloud account
2. `hcloud` and hcloud credentials configured
3. `kubectl`
4. `ansible`
{% hint style="warning" %}
**LINUX/MAC is the preferred method 프로젝트로 돌아가기