8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ubuntuでRKE2環境構築を行う方法

Last updated at Posted at 2021-07-01

#RKE2環境構築
RKE2とはRKE Governmentとしても知られているRancherの次世代Kubernetesディストリビューションのことです。

この記事ではインストールからクラスタ構成まで行います。

How is this different from RKE or K3s?
RKE2 combines the best-of-both-worlds from the 1.x version of RKE (hereafter referred to as RKE1) and K3s.
From K3s, it inherits the usability, ease-of-operations, and deployment model.
From RKE1, it inherits close alignment with upstream Kubernetes. In places K3s has diverged from upstream Kubernetes in order to optimize for edge deployments, but RKE1 and RKE2 can stay closely aligned with upstream.
Importantly, RKE2 does not rely on Docker as RKE1 does. RKE1 leveraged Docker for deploying and managing the control plane components as well as the container runtime for Kubernetes. RKE2 launches control plane components as static pods, managed by the kubelet. The embedded container runtime is containerd.

参照

##動作環境
vm名 anchor-1(サーバーノード)

  • Ubuntu 20.04.2 LTS
  • CPU 2コア
  • メモリ 4GB
  • ハードディスク 50GB

vm名 anchor-2, anchor-3(ワーカーノード)

  • Ubuntu 20.04.2 LTS
  • CPU 2コア
  • メモリ 4GB
  • ハードディスク 50GB

vm名 share-anchor(コントローラー)

  • Ubuntu 20.04.2 LTS
  • CPU 2コア
  • メモリ 4GB
  • ハードディスク 50GB

##インストール方法

###サーバーノードのインストール

anchor-1にsshする
ルート権限にする

anchor-1:~$ sudo -i

インストーラーを実行する

root@anchor-1:~# curl -sfL https://get.rke2.io | sh -
[INFO]  finding release for channel stable
[INFO]  using v1.20.8+rke2r1 as release
[INFO]  downloading checksums at https://github.com/rancher/rke2/releases/download/v1.20.8+rke2r1/sha256sum-amd64.txt
[INFO]  downloading tarball at https://github.com/rancher/rke2/releases/download/v1.20.8+rke2r1/rke2.linux-amd64.tar.gz
[INFO]  verifying tarball
[INFO]  unpacking tarball file to /usr/local

rke2-serverのサービスを有効化する

root@anchor-1:~# systemctl enable rke2-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/rke2-server.service → /usr/local/lib/systemd/system/rke2-server.service.

サービスを開始する

root@anchor-1:~# systemctl start rke2-server.service

###ワーカーノードのインストール

anchor-2にsshする
ルート権限にする

anchor-2:~$ sudo -i

インストーラーを実行する

root@anchor-2:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -
[INFO]  finding release for channel stable
[INFO]  using v1.20.8+rke2r1 as release
[INFO]  downloading checksums at https://github.com/rancher/rke2/releases/download/v1.20.8+rke2r1/sha256sum-amd64.txt
[INFO]  downloading tarball at https://github.com/rancher/rke2/releases/download/v1.20.8+rke2r1/rke2.linux-amd64.tar.gz
[INFO]  verifying tarball
[INFO]  unpacking tarball file to /usr/local

rke2-agentサービスを有効にする

root@anchor-2:~# systemctl enable rke2-agent.service

rke2-agentサービスを構成する

mkdir -p /etc/rancher/rke2/
vim /etc/rancher/rke2/config.yaml

config.yamlに書く内容
サーバーノードのトークンはanchor-1の/var/lib/rancher/rke2/server/tokenに書いてある

root@anchor-1:~# cat /var/lib/rancher/rke2/server/token
config.yaml
server: https://<server>:9345 #<server>にサーバーノードのIPアドレスを入れる
token: <token from server node> #サーバーノードのトークンを入れる

サービスを開始する

root@anchor-2:~# systemctl start rke2-agent.service

###コントローラーのインストール

kubectlのインストール

configファイルの変更

root@share-anchor:~# vim ~/.kube/config

configファイルに入力する内容はサーバーノードの/etc/rancher/rke2/rke2.yamlファイルの内容をコピーする
URLはサーバーノードのURLを入れる

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJlVENDQVIrZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWtNU0l3SUFZRFZRUUREQmx5YTJVeUxYTmwKY25abGNpMWpZVUF4TmpJMU1URTBPVEk0TUI0WERUSXhNRGN3TVRBME5EZzBPRm9YRFRNeE1EWXlPVEEwTkRnMApPRm93SkRFaU1DQUdBMVVFQXd3WmNtdGxNaTF6WlhKMlpYSXRZMkZBTVRZeU5URXhORGt5T0RCWk1CTUdCeXFHClNNNDlBZ0VHQ0NxR1NNNDlBd0VIQTBJQUJNa3Mwc1BTVG54VDdXKzBHNU0yZGpsOU55TlZzZy9C8rT0NScVEKSlg3dHFiNkhDbit1SDB5LzlNMWJiUlFKM2hxeVd4RjhNeTlDcVlzNERFSVNieEtqUWpCQU1BNEdBMVVkRHdFQgovd1FFQXdJQ3BEQVBCZ05WSFJNQkFmOEVCVEFEQVFIL01CMEdBMVVkRGdRV0JCUTlnUi9XVGRKSzNDdDhwU25ECmJCTnVMaytsbURBS0JnZ3Foa2pPUFFRREFnTklBREJGQWlFQTByaWloUjZQQmRqZGZzUld6YmVlMXdlRVVsdjQKSitsOXVKNzBENVpSUjVFQ0lDRWYyYkFuaVpSQVNoZHpIZ2E4ZmpJdHc3eE1NNXpyc3d5eHFiN1pDZTRpCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://192.168.10.20:6443
  name: default
contexts:
- context:
    cluster: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrakNDQVRpZ0F3SUJBZ0lJVk5tM2xIelZFSG93Q2dZSUtvWkl6ajBFQXdJd0pERWlNQ0FHQTFVRUF3d1oKY210bE1pMWpiR2xsYm5RdFkyRkFNVFl5TlRFeE5Ea3lPREFlRncweU1UQTNNREV3TkRRNE5EaGFGdzB5TWpBMwpNREV3TkRRNE5EaGFNREF4RnpBVkJnTlZCQW9URG5ONWMzUmxiVHB0WVhOMFpYSnpNUlV3RXdZRFZRUURFd3h6CmVYTjBaVzA2WVdSdGFXNHdXVEFUQmdjcWhrak9QUUlCQmdncWhrak9QUU1CQndOQ0FBUmZucHZkUDZXbmE1dkUKQUxLdTFjYlhlRFV1NUV5a2RENzVtc0xONU1ZUjIyakxHQUtPTXl1dnpUWmtBQk9jeDZpQWJ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kvUDNwMmIwbElTUDNiVmVLbDdRPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
    client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSU1kbTRhY2dmWkZ4MUlXTEQ0WGx1cC90d29QalpvUVB6NkxhMEFpbjZ1eC9vQW9HQ0NxR1NNNDkKQXdF9VUURRZ0FFWDU2YjNUK2xwMnVieEFDeXJ0WEcxM2cxTHVSTXBIUSsrWnJDemVUR0VkdG95eGdDampNcgpyODAyWkFBVG5NZW9nRzdlSDZML2lvd2Q0NC9HenlGb1p3PT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=

##インストール確認

クラスターが組めているかshare-anchorで確認してみる

root@share-anchor:~# kubectl get node
NAME       STATUS   ROLES                       AGE    VERSION
anchor-1   Ready    control-plane,etcd,master   140m   v1.20.8+rke2r1
anchor-2   Ready    <none>                      102m   v1.20.8+rke2r1
anchor-3   Ready    <none>                      42s    v1.20.8+rke2r1

##あとがき

よいkubernetes生活を!!!!!!

##参考資料

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?