配置安全证书的Etcd集群
不知在哪篇技术文档中看到,kubernetes master和etcd分开部署模式,因为集群的状态都保存在etcd中,这样当kubernetes master挂掉后,通过API Server交互的Scale等功能无法使用外,其他已经部署的Pod仍然能继续工作。
基于这种考虑,通过yum以及修改etcd.conf方式部署了一个三节点的etcd集群,但对于企业使用而言,虽然在局域网内访问,多数情况下还是需要配置安全证书,就好像很多政府部门因为三级等保的要求必须在weblogic中配置ssl一样,自己尝试在之前的环境中通过修改conf文件下配置,启动时遭遇各种问题失败,但同样的证书后修改为命令行方式配置后以及手工安装etcd后部署成功。记录如下:
- 安装cfssl
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
chmod +x cfssl_linux-amd64 cfssljson_linux-amd64
mv cfssl_linux-amd64 /usr/local/bin/cfssl
mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
- 创建CA
# mkdir /root/ssl
# cd /root/ssl
# cfssl print-defaults config > ca-config.json
# cfssl print-defaults csr > ca-csr.json
修改ca-config.json
[root@etc0 ssl]# cat ca-config.json
{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"kubernetes": {
"expiry": "8760h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
server auth表示client可以用该ca对server提供的证书进行验证
client auth表示server可以用该ca对client提供的证书进行验证
创建证书签名请求
[root@etc0 ssl]# cat ca-csr.json
{
"CN": "kubernetes",
"key": {
"algo": "rsa",
"size":
},
"names": [
{
"C": "US",
"L": "CA",
"ST": "San Francisco",
"O": "k8s",
"OU": "System"
}
]
}
生成CA证书和私钥
# cfssl gencert -initca ca-csr.json | cfssljson -bare ca
# ls ca*
ca-config.json ca.csr ca-csr.json ca-key.pem ca.pem
- 创建kubernetes证书
[root@etc0 ssl]# cat kubernetes-csr.json
{
"CN": "kubernetes",
"hosts": [
"127.0.0.1",
"192.168.0.102",
"192.168.0.103",
"192.168.0.104",
"192.168.0.105",
"192.168.0.106",
"10.254.0.1",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster",
"kubernetes.default.svc.cluster.local"
],
"key": {
"algo": "rsa",
"size":
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
可以看到该证书把etcd集群的所有ip,kubernetes master的所有ip以及kubernetes服务的ip(10.254.0.1)都加入进去了,这样他们都能使用同一个密钥
生成Kubernetes证书和密钥
# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kubernetes-csr.json | cfssljson -bare kubernetes
# ls kuberntes*
kubernetes.csr kubernetes-csr.json kubernetes-key.pem kubernetes.pem
- 分发证书文件
在每台etcd机器中运行
# mkdir -p /etc/kubernetes/ssl
# cp *.pem /etc/kubernetes/ssl
etcd集群配置
在/etc/hosts文件中加入地址
[root@etc0 ssl]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.102 etc0
192.168.0.103 etc1
192.168.0.104 etc2
- 手工下载和安装etcd
访问https://github.com/coreos/etcd/releases,我下载的是3.2.9版本
https://github.com/coreos/etcd/releases/download/v3.2.9/etcd-v3.2.9-linux-amd64.tar.gz
在每台机器上运行
tar -xvf etcd-v3.2.9-linux-amd64.tar.gz
mv etcd-v3.2.9-linux-amd64/etcd* /root/local/bin mkdir -p /var/lib/etcd
建立一个etcd.service文件,内容如下(针对不同的etcd节点需要修改ip地址和name)
[root@etc0 ssl]# cat /etc/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos [Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /root/local/bin/etcd --name=etc0 --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem --peer-cert-file=/etc/kubernetes/ssl/kubernetes.pem --peer-key-file=/etc/kubernetes/ssl/kubernetes-key.pem --trusted-ca-file=/etc/kubernetes/ssl/ca.pem --peer-trusted-ca-file=/etc/kubernetes/ssl/ca.pem --initial-advertise-peer-urls=https://192.168.0.102:2380 --listen-peer-urls=https://192.168.0.102:2380 --listen-client-urls=https://192.168.0.102:2379,https://127.0.0.1:2379 --advertise-client-urls=https://192.168.0.102:2379 --initial-cluster-token=etcd-cluster-0 --initial-cluster=\"etc0=https://192.168.0.102:2380,etc1=https://192.168.0.103:2380,etc2=https://192.168.0.104:2380\" --initial-cluster-state=new --data-dir=/var/lib/etcd"
Restart=on-failure
RestartSec=
LimitNOFILE= [Install]
WantedBy=multi-user.target
在每台etcd节点上启动etcd服务
# mv etcd.service /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable etcd
# systemctl start etcd
# systemctl status etcd
[root@etc1 bin]# systemctl status etcd
● etcd.service - Etcd Server
Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu -- :: CST; 1h 20min ago
Docs: https://github.com/coreos
Main PID: (etcd)
CGroup: /system.slice/etcd.service
└─ /root/local/bin/etcd --name=etc1 --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem... Oct :: etc1 etcd[]: lost the TCP streaming connection with peer 70df68d0b37fcd43 (stream MsgApp v2 reader)
Oct :: etc1 etcd[]: failed to dial 70df68d0b37fcd43 on stream Message (dial tcp 192.168.0.104:: getsockopt: connection refused)
Oct :: etc1 etcd[]: peer 70df68d0b37fcd43 became inactive
Oct :: etc1 etcd[]: peer 70df68d0b37fcd43 became active
Oct :: etc1 etcd[]: closed an existing TCP streaming connection with peer 70df68d0b37fcd43 (stream MsgApp v2 writer)
Oct :: etc1 etcd[]: established a TCP streaming connection with peer 70df68d0b37fcd43 (stream MsgApp v2 writer)
Oct :: etc1 etcd[]: closed an existing TCP streaming connection with peer 70df68d0b37fcd43 (stream Message writer)
Oct :: etc1 etcd[]: established a TCP streaming connection with peer 70df68d0b37fcd43 (stream Message writer)
Oct :: etc1 etcd[]: established a TCP streaming connection with peer 70df68d0b37fcd43 (stream Message reader)
Oct :: etc1 etcd[]: established a TCP streaming connection with peer 70df68d0b37fcd43 (stream MsgApp v2 reader)
如果出现任何错误,可以通过journalctl -xe去看到启动详情。
- 验证服务
[root@etc1 bin]# ./etcdctl --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem --endpoints=https://192.168.0.102:2379,https://192.168.0.103:2379,https://192.168.0.104:2379 cluster-health
member 4701789a3a673ef5 is healthy: got healthy result from https://192.168.0.103:2379
member 70df68d0b37fcd43 is healthy: got healthy result from https://192.168.0.104:2379
member 90262c9df511cc4d is healthy: got healthy result from https://192.168.0.102:2379
cluster is healthy
如果不带证书访问,报错信息为
[root@etc1 bin]# ./etcdctl --endpoints=https://192.168.0.102:2379,https://192.168.0.103:2379,https://192.168.0.104:2379 cluster-health
cluster may be unhealthy: failed to list members
Error: client: etcd cluster is unavailable or misconfigured; error #: x509: certificate signed by unknown authority
; error #: x509: certificate signed by unknown authority
; error #: x509: certificate signed by unknown authority error #: x509: certificate signed by unknown authority
error #: x509: certificate signed by unknown authority
error #: x509: certificate signed by unknown authority
- 目前的问题是:
为什么通过手工方式修改conf文件不成?
配置安全证书的Etcd集群的更多相关文章
- 二进制搭建kubernetes多master集群【一、使用TLS证书搭建etcd集群】
上一篇我们介绍了kubernetes集群架构以及系统参数配置,参考:二进制搭建kubernetes多master集群[开篇.集群环境和功能介绍] 下面本文etcd集群才用三台centos7.5搭建完成 ...
- Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列之自签TLS证书及Etcd集群部署(二)
0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 一.服务器设置 1.把每一 ...
- kubernetes 集群安装etcd集群,带证书
install etcd 准备证书 https://www.kubernetes.org.cn/3096.html 在master1需要安装CFSSL工具,这将会用来建立 TLS certificat ...
- Kubernetes集群搭建之Etcd集群配置篇
介绍 etcd 是一个分布式一致性k-v存储系统,可用于服务注册发现与共享配置,具有以下优点. 简单 : 相比于晦涩难懂的paxos算法,etcd基于相对简单且易实现的raft算法实现一致性,并通过g ...
- CentOS 7 ETCD集群配置大全
目录 前言 环境准备 安装 静态集群 配置 node01 配置文件 node02 配置文件 node03 配置文件 启动测试 查看集群状态 生成TLS证书 etcd证书创建 安装cfssl工具集 生成 ...
- K8s二进制部署单节点 etcd集群,flannel网络配置 ——锥刺股
K8s 二进制部署单节点 master --锥刺股 k8s集群搭建: etcd集群 flannel网络插件 搭建master组件 搭建node组件 1.部署etcd集群 2.Flannel 网络 ...
- 使用docker配置etcd集群
docker配置etcd集群与直接部署etcd集群在配置上并没有什么太大差别. 我这里直接使用docker-compose来实现容器化的etcd部署 环境如下: HostName IP etcd1 1 ...
- kubeadm配置高可用etcd集群
操作系统为ubuntu18 kubernetes版本为v1.15.1 k8s默认在控制平面节点上的kubelet管理的静态pod中运行单个成员的etcd集群,但这不是高可用的方案. etcd高可用集群 ...
- Centos7下Etcd集群搭建
一.简介 "A highly-available key value store for shared configuration and service discovery." ...
随机推荐
- 4:django url
一个干净的,优雅的URL 方案是一个高质量Web 应用程序的重要细节. 这节我们来看看django是如何做到干净优雅的url的 1:Django如何处理一个请求 通过ROOT_URLCONF决定根UR ...
- MyBatis3-与Spring 4集成
继续使用前一篇的例子http://www.cnblogs.com/EasonJim/p/7052368.html,实际项目中,通常会用Spring来管理DataSource等.充分利用Spring基于 ...
- HDU 3045 picnic cows(斜率DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 题目大意:有n个数,可以把n个数分成若干组,每组不得小于m个数,每组的价值=除了该组最小值以外每 ...
- Fel表达式计算引擎学习
转载原文地址:Fel是轻量级的高效的表达式计算引擎 Fel的问题 Fel的问题 Fel是轻量级的高效的表达式计算引擎 Fel在源自于企业项目,设计目标是为了满足不断变化的功能需求和性能需求. Fel是 ...
- Python 分页功能
自定义分页组件 """ 自定义分页组件的使用方法: pager_obj = Pagination(request.GET.get('page',1),len(HOST_L ...
- CentOS7安装和配置rsync+inotify
(1)rsync介绍 1.rsync介绍 开源,实现全量及增量的本地或远程数据同步备份工具 2.工作场景: 存储实时备份:rsync+inotify 定时备份:rsync+crond 3.rsync工 ...
- coercing to Unicode错误的一个解决办法
http://blog.csdn.net/happen23/article/details/46683813
- Qt精简编译方法总结
原文请看:http://blog.csdn.net/loaden/article/details/6061702 Qt如果采取默认编译安装,一般都要占用上G的空间.当初自己不想涉及Qt的一个原因,就是 ...
- python全局变量被覆盖的问题
下面的情况,foo全局变量会被局部变量覆盖掉,这样在其它地方使用的值就是空值. g_foo = '' #全局变量 def set(): g_foo = 'abc' # 给全局变量赋值 def use_ ...
- [scrapy] scrapy 使用goose作为正文提取
import scrapy from goose import Goose class Article(scrapy.Item): title = scrapy.Field() text = scra ...