当前位置:网站首页>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/
边栏推荐
- Generation of tables and contingency tables (cross tables) of R language factor data: use the summary function to analyze the list, view the chi square test results, and judge whether the two factor v
- 线程阻塞的三种情况。
- The strongest distributed locking tool: redisson
- 彻底掌握二分查找
- 了解虚拟列表背后原理,轻松实现虚拟列表
- Holes in [apue] files
- 修订版 | 目标检测:速度和准确性比较(Faster R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)...
- 【Try to Hack】HFish蜜罐部署
- Postgresql14 installation and master-slave configuration
- R language test sample proportion: use prop The test function performs the single sample proportion test to calculate the confidence interval of the p value of the successful sample proportion in the
猜你喜欢

Qt5开发从入门到精通——第一篇概述

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

IP黑白名单

深度学习基础----GNN谱域和空域 (不断完善更新积累)

Record a fake login of cookie

Security assurance is based on software life cycle -istio authorization mechanism

Machine learning (Zhou Zhihua) Chapter 6 notes on Support Vector Learning

30 day question brushing plan (IV)

Istio四之故障注入和链路追踪

【飞控开发基础教程7】疯壳·开源编队无人机-SPI(气压计数据获取)
随机推荐
Uva1599 ideal path problem solution
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用confint函数给出回归系数的95%置信区间
Poj3259 wormhole solution
Duplicate data in leetcode (442) array
最强分布式锁工具:Redisson
R language uses LM function to build linear regression model and subset function to specify subset of data set to build regression model (use floor function and length function to select the former pa
DXF reading and writing: Chinese description of dimension style group codes
leetcode(442)数组中重复的数据
《机器学习》(周志华) 第6章 支持向量 学习心得 笔记
了解虚拟列表背后原理,轻松实现虚拟列表
QT自制软键盘 最完美、最简单、跟自带虚拟键盘一样
Implementation of StrCmp, strstr, memcpy, memmove
浅谈WebSocket
Diablo 4 ps4/ps5 beta has been added to the Playstation database
url相关知识点
修订版 | 目标检测:速度和准确性比较(Faster R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)...
DXF reading and writing: align the calculation of the position of the dimension text in the middle and above
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize violin diagrams, set the palette parameter, and customize the border colors of violin diagrams at different l
正则表达式
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question