当前位置:网站首页>Read how to deploy highly available k3s with external database
Read how to deploy highly available k3s with external database
2022-07-28 14:07:00 【InfoQ】
Introduce
HA To configure

Environmental Science
10.161.129.5410.161.129.15410.161.129.19610.161.129.21210.161.129.118install Postgres
Postgres virtual machine
- Use zypper install Postgres package :
zypper -n in postgresql10 postgresql10-server
systemctl start postgresql- establish K3s database 、 User role and grant all access rights to user role :
sudo -u postgres psql
create database K3s;
create user K3s with encrypted password 'K3s';
grant all privileges on database K3s to K3s;
exit;K3sK3s- Create logo Postgres The self signed certificates of the server and store them in
/var/lib/pgsql/data/in :
openssl req -new -x509 -days 365 -nodes -text -out /var/lib/pgsql/data/postgres.crt -keyout /var/lib/pgsql/data/postgres.key -subj "/CN=postgres.rancher.rke2" -addext "subjectAltName=DNS:postgres.rancher.rke2"- Ensure that access to the private key is restricted :
chmod 0600 /var/lib/pgsql/data/postgres.key
chown postgres:postgres /var/lib/pgsql/data/postgres.key- Mark Postgres Copy the public key certificate of to two K3s Server, send K3s Server Can verify Postgres To carry out SSL signal communication :
scp /var/lib/pgsql/data/postgres.crt [email protected]:
scp /var/lib/pgsql/data/postgres.crt [email protected]:- take
/var/lib/pgsql/data/pg_hba.confReplace with the following :
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections onlyf
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
hostssl all all 0.0.0.0/0 md5 clientcert=verify-fullK3s Server 1 virtual machine
- Create a logo K3s Cluster self signed certificate , And grant private key permission :
openssl req -new -x509 -days 365 -nodes -text -out K3s.crt -keyout K3s.key -subj "/CN=K3s" -addext "subjectAltName=DNS:K3s"
chmod 0600 K3s.key- Copy the public key certificate to Postgres host , In order to Postgres Can verify K3s client :
scp /home/sles/K3s.crt [email protected]:- Copy public and private keys to other K3s Server. Two sets of Server form K3s colony :
scp /home/sles/K3s.crt /home/sles/K3s.key [email protected]:Postgres virtual machine
- take K3s.crt Move to
/var/lib/pgsql/dataThe catalogue is for Postgres Configuration file usage :
mv /home/sles/K3s.crt /var/lib/pgsql/data/- take
/var/lib/pgsql/data/postgresql.confThe content of is modified to the following value :
listen_addresses = '*'
ssl = on
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_dh_params_file = ''
ssl_cert_file = '/var/lib/pgsql/data/postgres.crt'
ssl_key_file = '/var/lib/pgsql/data/postgres.key'
ssl_ca_file = '/var/lib/pgsql/data/K3s.crt'listen_addresses*sslssl_cert_filessl_key_filessl_ca_filessl_ca_file- restart Postgres Server to apply the new configuration :
systemctl restart postgresqlK3s Server 1 virtual machine
- Install with the correct flags and values K3s Server:
curl -sfL https://get.k3s.io | sh -s - server --datastore-endpoint="postgres://K3s:[email protected]:5432/K3s" --datastore-cafile="/home/sles/postgres.crt" --token=K3s --datastore-certfile="/home/sles/K3s.crt" --datastore-keyfile="/home/sles/K3s.key" --tls-san=10.161.129.118--datastore-endpointpostgres://username:[email protected]:port/database-nameK3sK3sK3spostgres.rancher.rke--datastore-cafile--datastore-certfile--datastore-keyfile--token--tls-san- In order to make K3s analysis
postgres.rancher.rke2, I am here/``etc/hostsThe following contents are attached at the end of the document :
10.161.129.212 postgres.rancher.rke210.161.129.212- Now? , verification K3s Server Is it working properly and connected to Postgres:
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
kubectl get pods -Arunningjournalctl -xeK3s Server 2 virtual machine
- Use and install the first Server Use the same command to install the second K3s Server:
curl -sfL https://get.k3s.io | sh -s - server --datastore-endpoint="postgres://K3s:[email protected]:5432/K3s" --datastore-cafile="/home/sles/postgres.crt" --token=K3s --datastore-certfile="/home/sles/K3s.crt" --datastore-keyfile="/home/sles/K3s.key" --tls-san=10.161.129.118- verification K3s Server Is it working properly and connected to Postgres:
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
kubectl get pods -ANAMESPACE NAME READY STATUS RESTARTS AGE
kube-system svclb-traefik-55frd 2/2 Running 0 11m
kube-system svclb-traefik-x59vc 2/2 Running 0 2m43s
kube-system local-path-provisioner-6c79684f77-55tkc 1/1 Running 0 107s
kube-system coredns-d76bd69b-5n8s7 1/1 Running 0 107s
kube-system traefik-df4ff85d6-88phx 1/1 Running 0 107s
kube-system metrics-server-7cd5fcb6b7-x7t2r 1/1 Running 0 107s- You can also check whether there are two in the cluster by running this command Server, And see if they have
masterrole :
kubectl get nodesNAME STATUS ROLES AGE VERSION
k3s-server-1 Ready control-plane,master 14m v1.23.6+K3s1
k3s-server-2 Ready control-plane,master 29s v1.23.6+K3s1Nginx Load balancer virtual machine
- install Nginx package :
zypper in nginx- establish
/etc/nginx/nginx.confFile and enter the following :
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
worker_processes 4;
worker_rlimit_nofile 40000;
events {
worker_connections 8192;
}
stream {
log_format logs '$remote_addr - - [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$upstream_addr"';
access_log /var/log/nginx/access.log logs;
upstream K3s_api_server {
least_conn;
server 10.161.129.54:6443 max_fails=3 fail_timeout=5s;
server 10.161.129.154:6443 max_fails=3 fail_timeout=5s;
}
server {
listen 6443;
proxy_pass K3s_api_server;
}least_conn- restart Nginx For changes to take effect :
nginx -s reload
systemctl reload nginx && systemctl restart nginxK3s Agent virtual machine
- Use the following command to install K3s Agent.
--servercurl -sfL https://get.k3s.io | sh -s - agent --token=K3s --server https://10.161.129.118:6443K3s Server 1 virtual machine
- Now? , You can check by running this command K3s Agent Have you successfully registered :
kubectl get nodesNAME STATUS ROLES AGE VERSION
k3s-server-1 Ready control-plane,master 41m v1.23.6+K3s1
k3s-server-2 Ready control-plane,master 28m v1.23.6+K3s1
k3s-agent Ready <none> 105s v1.23.6+K3s1Reference resources
- K3s Schema document :https://rancher.com/docs/k3s/latest/en/architecture/#high-availability-with-an-external-db
- K3s Data storage documents :https://rancher.com/docs/k3s/latest/en/installation/datastore/
- K3s Installation document :https://rancher.com/docs/k3s/latest/en/installation/ha/
- Nginx Load balancer documentation :https://rancher.com/docs/rancher/v2.5/en/installation/resources/k8s-tutorials/infrastructure-tutorials/nginx/
边栏推荐
- DXF reading and writing: align the calculation of the position of the dimension text in the middle and above
- 83.(cesium之家)cesium示例如何运行
- The strongest distributed locking tool: redisson
- Implementation of StrCmp, strstr, memcpy, memmove
- 线程阻塞的三种情况。
- Thoroughly master binary search
- a标签_文件下载(download属性)
- Tutorial on the principle and application of database system (061) -- MySQL exercise: operation questions 21-31 (V)
- Socket类关于TCP字符流编程的理解学习
- Postgresql14安装及主从配置
猜你喜欢

Jmeter安装教程及登录增加token

Understanding of "image denoising using an improved generic advantageous network with Wasserstein distance"

SLAM论文合集

论文研读--Masked Generative Distillation

Record a fake login of cookie
![[security] read rfc6749 and understand the authorization code mode under oauth2.0](/img/dc/e6d8626195b2e09a6c06050a9b552e.jpg)
[security] read rfc6749 and understand the authorization code mode under oauth2.0

安全保障基于软件全生命周期-PSP应用

Socket类关于TCP字符流编程的理解学习

30 day question brushing plan (II)

基于NoneBot2的qq机器人配置记录
随机推荐
Uva11175 digraph D and E from D to e and back
leetcode(442)数组中重复的数据
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用confint函数给出回归系数的95%置信区间
Leetcode depth first and breadth first traversal
MySql5.5之后的默认存储引擎为InnoDB。
Duplicate data in leetcode (442) array
R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
Implementation of StrCmp, strstr, memcpy, memmove
leetcode-深度优先与广度优先遍历
作为一个程序员,如何高效的管理时间?
解决跨越的几种方案
url相关知识点
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
Tutorial on the principle and application of database system (062) -- MySQL exercise questions: operation questions 32-38 (6)
Uva1599 ideal path problem solution
记一次COOKIE的伪造登录
安全保障基于软件全生命周期-NetworkPolicy应用
Poj3268 shortest path solution
Long closed period private placement products reappearance industry insiders have different views