当前位置:网站首页>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/
边栏推荐
- 【LVGL事件(Events)】事件在不同组件上的应用(一)
- jenkins
- TS literacy method - Basic chapter
- Vite configuring path aliases in the project
- strcmp、strstr、memcpy、memmove的实现
- 【Utils】JsonUtil
- Tutorial on the principle and application of database system (059) -- MySQL exercise questions: operation questions 1-10 (III)
- Security assurance is based on software life cycle -psp application
- [lvgl events] Application of events on different components (I)
- On websocket
猜你喜欢

算法---不同路径(Kotlin)

Socket class understanding and learning about TCP character stream programming

How to play a data mining game entry Edition

The strongest distributed locking tool: redisson

Security assurance is based on software life cycle -psp application

7. Dependency injection

LeetCode 105.从前序与中序遍历序列构造二叉树 && 106.从中序与后序遍历序列构造二叉树

Record a fake login of cookie

目标检测:速度和准确性比较(Fater R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)

《机器学习》(周志华) 第6章 支持向量 学习心得 笔记
随机推荐
走进音视频的世界——FLV视频封装格式
IntersectionObserver交叉观察器
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的边框颜色
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
Slam thesis collection
掌握闭包,夯实基本功
leetcode-深度优先与广度优先遍历
【翻译】盐业公司来Linkerd公司是为了负载平衡,留下来是为了效率、可靠性和性能。...
Operator3 - design an operator
【飞控开发基础教程7】疯壳·开源编队无人机-SPI(气压计数据获取)
【Utils】FastDFS工具类
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
Security assurance is based on software life cycle -istio authentication mechanism
R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)
第六章 支持向量机
什么是自旋锁 自旋锁是指当一个线程尝试获取某个锁时,如果该锁已被其他线程占用,就一直循环检测锁是否被释放,而不是进入线程挂起或睡眠状态。 /** * 为什么用自旋锁:多个线程对同一个变量
【Utils】CookieUtil
【Try to Hack】HFish蜜罐部署
What is the reason why the words behind word disappear when typing? How to solve it?
软件测试技术之如何编写测试用例