AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1001778
Accepted
uav
uav
Asked: 2020-02-05 11:02:32 +0800 CST2020-02-05 11:02:32 +0800 CST 2020-02-05 11:02:32 +0800 CST

自己的 Kubernetes etcd 集群

  • 772

我想在两个位置(距离 300 公里)构建自己的 Kubernetes 集群并将其集成到 GitLab。

让我列出我的想法。我的问题是我的想法是否有错误并要求解决它。

  1. 由于我只能设置虚拟机并且没有直接在主机上的权限,因此我想在 5 个虚拟机(3+2)上安装一个 etcd-cluster。我会在 Ubuntu 18.04 上使用 apt 安装 etcd。为此,我一开始不需要 Kubernetes。

  2. 奇数个实例仅适用于 etcd 而不适用于控制平面?

  3. 为控制平面设置单独的虚拟机是否有意义,或者我可以重用 etcd 集群的 3+2 个虚拟机吗?否则我已经有 10 个虚拟机了。

kubernetes etcd
  • 2 2 个回答
  • 293 Views

2 个回答

  • Voted
  1. Best Answer
    c4f4t0r
    2020-02-05T11:45:29+08:002020-02-05T11:45:29+08:00

    除非您有一个包含数千个服务和许多节点的大型 kubernetes 集群,否则您可以设置一个单独的 etcd 集群并记住如果您想在两个位置设置 etcd 集群,请查看 coreos 文档,因为 etcd 对延迟非常敏感

    如果选择使用外部 etcd 集群,控制平面不需要奇数,etcd 只需要奇数,因为 etcd 机器在集群中。

    控制平面之间不通信,仅与 etcd 通信

    • 2
  2. uav
    2020-02-09T09:34:57+08:002020-02-09T09:34:57+08:00

    我学到了一些东西,想和你分享。

    etcd 的发音类似于“@cee dee”。

    我现在决定不使用 apt(Ubuntu 18.04 上的 etcd 3.2)进行安装,而是使用 wget 下载最新版本(3.3.18)。谷歌的第一次成功奏效了。

    安装

    cd /opt/
    sudo wget https://github.com/etcd-io/etcd/releases/download/v3.3.18/etcd-v3.3.18-linux-amd64.tar.gz
    sudo tar xvf etcd-v3.3.18-linux-amd64.tar.gz
    cd etcd-v3.3.18-linux-amd64/
    sudo mv etcd etcdctl /usr/local/bin/
    sudo mkdir -p /var/lib/etcd/
    sudo mkdir /etc/etcd/
    sudo groupadd --system etcd
    sudo useradd -s /sbin/nologin --system -g etcd etcd
    sudo chown -R etcd:etcd /var/lib/etcd/
    

    重置

    删除成员文件夹中的所有数据:

    sudo rm /etc/etcd/*.etcd/member/ /opt/etcd-v*-linux-amd64/default.etcd/member/ /var/lib/etcd/member/ -fr
    

    或更改参数--initial-cluster-token XYZ(每五个成员相同)并etcd以 parameter开头--force-new-cluster。

    当您重新启动现有集群或添加更多成员时:从 更改--initial-cluster-state new为--initial-cluster-state existing。

    从 etcd 集群中删除所有数据(带有值的键):

    sudo ETCDCTL_API=3 etcdctl del "" --prefix
    

    配置

    sudo -u etcd etcd \
    --name aaa \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.101:2380,http://192.168.4.101:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.101:2379,http://192.168.4.101:4001 \
    --initial-advertise-peer-urls http://192.168.4.101:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.101:2379
    
    sudo -u etcd etcd \
    --name bbb \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.102:2380,http://192.168.4.102:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.102:2379,http://192.168.4.102:4001 \
    --initial-advertise-peer-urls http://192.168.4.102:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.102:2379
    
    sudo -u etcd etcd \
    --name ccc \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.103:2380,http://192.168.4.103:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.103:2379,http://192.168.4.103:4001 \
    --initial-advertise-peer-urls http://192.168.4.103:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.103:2379
    
    sudo -u etcd etcd \
    --name ddd \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.104:2380,http://192.168.4.104:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.104:2379,http://192.168.4.104:4001 \
    --initial-advertise-peer-urls http://192.168.4.104:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.104:2379
    
    sudo -u etcd etcd \
    --name eee \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.105:2380,http://192.168.4.105:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.105:2379,http://192.168.4.105:4001 \
    --initial-advertise-peer-urls http://192.168.4.105:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.105:2379
    

    您可以将其投入使用:

    /etc/systemd/system/etcd.service(如果不存在则创建)(第一个成员 aaa 的示例)

    [Unit]
    Description=etcd key-value store
    Documentation=https://github.com/etcd-io/etcd
    After=network.target
    
    [Service]
    User=etcd
    Type=notify
    Environment=ETCD_DATA_DIR=/var/lib/etcd
    Environment=ETCD_NAME=%m
    ExecStart=/usr/local/bin/etcd \
    --name aaa \
    --data-dir /var/lib/etcd/ \
    --listen-peer-urls http://localhost:2380,http://localhost:7001,http://192.168.4.101:2380,http://192.168.4.101:7001 \
    --listen-client-urls http://localhost:2379,http://localhost:4001,http://192.168.4.101:2379,http://192.168.4.101:4001 \
    --initial-advertise-peer-urls http://192.168.4.101:2380 \
    --initial-cluster aaa=http://192.168.4.101:2380,bbb=http://192.168.4.102:2380,ccc=http://192.168.4.103:2380,eee=http://192.168.4.105:2380,ddd=http://192.168.4.104:2380 \
    --initial-cluster-state new \
    --initial-cluster-token 2020-02-07T14:53 \
    --advertise-client-urls http://192.168.4.101:2379
    Restart=always
    RestartSec=10s
    LimitNOFILE=40000
    
    sudo systemctl daemon-reload
    # sudo systemctl enable etcd  # for auto start after reboot
    sudo systemctl restart etcd
    

    如果有人可以做一个加密的例子,即使用客户端证书,我将不胜感激。

    计时码表

    同样重要的是所有五台机器都具有相同的时间。否则你会在你的日志中看到很多错误。为此,我使用了chrony。

    sudo timedatectl set-timezone Europe/Berlin
    sudo timedatectl set-local-rtc 1 --adjust-system-clock
    sudo timedatectl set-local-rtc 0
    sudo systemctl stop systemd-timesyncd.service && sudo systemctl disable systemd-timesyncd.service
    sudo apt update && sudo apt --yes install chrony
    

    /etc/chrony/chrony.conf

    # I use HTTP connect proxy and can't connect to external ntp servers:
    local
    bindcmdaddress 0.0.0.0
    allow 192.168.0.0/16
    cmdallow 192.168.0.0/16
    # server 192.168.4.101 prefer iburst  # himself
    server 192.168.4.102 prefer iburst
    server 192.168.4.103 prefer iburst
    server 192.168.4.104  prefer iburst
    server 192.168.4.105  prefer iburst
    # ...
    makestep 1 -1
    
    # Show time etc.:
    sudo timedatectl
    # Show ntp network members:
    sudo chronyc sources
    

    请记住也为工作节点提供相同的时间。

    检查

    sudo etcdctl cluster-health

    member eee6e5e8935fd1c9 is healthy: got healthy result from http://192.168.4.105:2379
    member bbb7b0aca4c13cdc is healthy: got healthy result from http://192.168.4.102:2379
    member aaac5ad73f7d224f is healthy: got healthy result from http://192.168.4.101:2379
    member ccc20379b7c3a64e is healthy: got healthy result from http://192.168.4.103:2379
    member ddd76f34bf32390e is healthy: got healthy result from http://192.168.4.104:2379
    cluster is healthy
    

    sudo etcdctl member list

    eee6e5e8935fd1c9: name=eee peerURLs=http://192.168.4.105:2380 clientURLs=http://192.168.4.105:2379 isLeader=false
    bbb7b0aca4c13cdc: name=bbb peerURLs=http://192.168.4.102:2380 clientURLs=http://192.168.4.102:2379 isLeader=false
    aaac5ad73f7d224f: name=aaa peerURLs=http://192.168.4.101:2380 clientURLs=http://192.168.4.101:2379 isLeader=true
    ccc20379b7c3a64e: name=ccc peerURLs=http://192.168.4.103:2380 clientURLs=http://192.168.4.103:2379 isLeader=false
    ddd76f34bf32390e: name=ddd peerURLs=http://192.168.4.104:2380 clientURLs=http://192.168.4.104:2379 isLeader=false
    
    
    • 1

相关问题

  • 无法通过 Docker 在本地运行 Hyperkube (kubernetes)

  • 跨 Kubernetes 分散工作负载

  • Kubernetes升级回滚机器类型

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve