linux运维、架构之路-Kubernetes1.13离线集群部署双向认证

一、部署环境

1、服务器规划


IP地址


主机名


CPU


内存


10.0.0.100


k8s-master01


2C


2G


10.0.0.101


k8s-node01


2C


2G


10.0.0.102


k8s-node02


2C


2G

2、Kubernetes 1.13包下载

https://github.com/kubernetes/kubernetes/releases

所用到包的版本:

3、Kubernetes工作流程

4、Kubernetes部署前准备

①系统环境

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[[email protected]-master01 ~]# uname -r
3.10.0-957.21.3.el7.x86_64
[[email protected]-master01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[[email protected]-master01 ~]# getenforce
Disabled

②关闭Swap

swapoff -a && sysctl -w vm.swappiness=0
vim /etc/fstab
UUID=b6ff8dda-f2db-49ad-a091-bdd4e82cdace /                       xfs     defaults        0 0
UUID=f4eaa64a-f9c7-4e11-a78b-13d423ac65d2 /boot                   xfs     defaults        0 0
#UUID=bc4d148a-56e0-4fa8-96a2-d10e5470963c swap                    swap    defaults        0 0

③设置Docker所需参数

cat << EOF | tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf

二、部署 Docker(所有节点)

1、安装

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce -y
systemctl start docker && systemctl enable docker

2、创建安装所需目录

mkdir /k8s/etcd/{bin,cfg,ssl} -p
mkdir /k8s/kubernetes/{bin,cfg,ssl} -p

3、安装生成证书工具CFSSL(Master节点)

mkdir tools && cd tools
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64
mv cfssl_linux-amd64 /usr/local/bin/cfssl
mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
mv cfssl-certinfo_linux-amd64 /usr/bin/cfssl-certinfo

4、创建认证证书(Master节点)

①创建 ETCD 证书

cat << EOF | tee ca-config.json
{
  "signing": {
    "default": {
      "expiry": "87600h"
    },
    "profiles": {
      "www": {
         "expiry": "87600h",
         "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ]
      }
    }
  }
}
EOF

创建 ETCD CA 配置文件  

cat << EOF | tee ca-csr.json
{
    "CN": "etcd CA",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Shenzhen",
            "ST": "Shenzhen"
        }
    ]
}
EOF

创建 ETCD Server 证书

cat << EOF | tee server-csr.json
{
    "CN": "etcd",
    "hosts": [
    "10.0.0.100",
    "10.0.0.101",
    "10.0.0.102"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Shenzhen",
            "ST": "Shenzhen"
        }
    ]
}
EOF

生成 ETCD CA 证书和私钥

cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server

②创建 Kubernetes CA 证书

cat << EOF | tee ca-config.json
{
  "signing": {
    "default": {
      "expiry": "87600h"
    },
    "profiles": {
      "kubernetes": {
         "expiry": "87600h",
         "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ]
      }
    }
  }
}
EOF
cat << EOF | tee ca-csr.json
{
    "CN": "kubernetes",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Shenzhen",
            "ST": "Shenzhen",
            "O": "k8s",
            "OU": "System"
        }
    ]
}
EOF

生成Kubernetes 证书和秘钥

cfssl gencert -initca ca-csr.json | cfssljson -bare ca -

③生成API_SERVER证书

cat << EOF | tee server-csr.json
{
    "CN": "kubernetes",
    "hosts": [
      "10.0.0.1",
      "127.0.0.1",
      "10.0.0.100",
      "kubernetes",
      "kubernetes.default",
      "kubernetes.default.svc",
      "kubernetes.default.svc.cluster",
      "kubernetes.default.svc.cluster.local"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Shenzhen",
            "ST": "Shenzhen",
            "O": "k8s",
            "OU": "System"
        }
    ]
}
EOF

生成API_SERVER证书和秘钥

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes server-csr.json | cfssljson -bare server

④创建 Kubernetes Proxy 证书

cat << EOF | tee kube-proxy-csr.json
{
  "CN": "system:kube-proxy",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "L": "Shenzhen",
      "ST": "Shenzhen",
      "O": "k8s",
      "OU": "System"
    }
  ]
}
EOF

生成Kubernetes Proxy 证书和秘钥

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy

5、ssh-key免秘钥认证

ssh-keygen

ssh-copy-id 10.0.0.101
ssh-copy-id 10.0.0.102

三、部署ETCD服务

1、上传解压文件

tar xf etcd-v3.3.10-linux-amd64.tar.gz
cd etcd-v3.3.10-linux-amd64/
cp etcd etcdctl /k8s/etcd/bin/

2、创建ETCD配置文件

vim /k8s/etcd/cfg/etcd

#[Member]
ETCD_NAME="etcd01"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.0.0.100:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.0.0.100:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.0.0.100:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.0.0.100:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://10.0.0.100:2380,etcd02=https://10.0.0.101:2380,etcd03=https://10.0.0.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

创建 etcd的 systemd unit 文件

vim /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=/k8s/etcd/cfg/etcd
ExecStart=/k8s/etcd/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} --initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} --initial-cluster=${ETCD_INITIAL_CLUSTER} --initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} --initial-cluster-state=new --cert-file=/k8s/etcd/ssl/server.pem --key-file=/k8s/etcd/ssl/server-key.pem --peer-cert-file=/k8s/etcd/ssl/server.pem --peer-key-file=/k8s/etcd/ssl/server-key.pem --trusted-ca-file=/k8s/etcd/ssl/ca.pem --peer-trusted-ca-file=/k8s/etcd/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

拷贝证书文件

cd tools
cp ca*pem server*pem /k8s/etcd/ssl

将启动文件、配置文件分发到 节点1、节点2

cd /k8s
scp -r etcd 10.0.0.101:/k8s/
scp -r etcd 10.0.0.102:/k8s/
scp /usr/lib/systemd/system/etcd.service  10.0.0.101:/usr/lib/systemd/system/etcd.service
scp /usr/lib/systemd/system/etcd.service  10.0.0.102:/usr/lib/systemd/system/etcd.service

修改节点1、节点2配置文件

vim /k8s/etcd/cfg/etcd

#[Member]
ETCD_NAME="etcd02"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.0.0.101:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.0.0.101:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.0.0.101:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.0.0.101:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://10.0.0.100:2380,etcd02=https://10.0.0.101:2380,etcd03=https://10.0.0.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
vim /k8s/etcd/cfg/etcd

#[Member]
ETCD_NAME="etcd03"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.0.0.102:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.0.0.102:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.0.0.102:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.0.0.102:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://10.0.0.100:2380,etcd02=https://10.0.0.101:2380,etcd03=https://10.0.0.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

3、启动ETCD服务

systemctl daemon-reload
systemctl enable etcd
systemctl start etcd

4、验证集群是否正常运行

/k8s/etcd/bin/etcdctl --ca-file=/k8s/etcd/ssl/ca.pem --cert-file=/k8s/etcd/ssl/server.pem --key-file=/k8s/etcd/ssl/server-key.pem --endpoints="https://10.0.0.100:2379,\
https://10.0.0.101:2379,\
https://10.0.0.102:2379" cluster-health
member 5db3ea816863435 is healthy: got healthy result from https://10.0.0.102:2379
member 991b5845cecb31b is healthy: got healthy result from https://10.0.0.101:2379
member c67ee2780d64a0d4 is healthy: got healthy result from https://10.0.0.100:2379
cluster is healthy

注意:
启动ETCD集群同时启动二个节点,启动一个节点集群是无法正常启动的;

原文地址:https://www.cnblogs.com/yanxinjiang/p/11247834.html

时间: 2024-11-05 18:48:15

linux运维、架构之路-Kubernetes1.13离线集群部署双向认证的相关文章

Linux运维 第五阶段(一)集群相关概念及LVS(LB)

一.集群相关概念 1.cluster-LB(load balancing) http(stateless无状态协议,就算使用长连接也有时间限定) 每一页面有众多的web object 若一台server配置4Gmemory,2*cpu:若同时200个请求中有50个dynamic(200个网络IO.磁盘IO都由CPU处理,150*2M=50*10M=800M):若200à1000个请求(1000个请求中200个dynamic,800*2M=200*10M=3.6G,除网络IO磁盘IO还有CS进程间

Linux运维学习之keepalived实现高可用集群

集群技术是一种较新的技术,通过集群技术,可以在付出较低成本的情况下获得在性能.可靠性.灵活性方面的相对较高的收益,其任务调度则是集群系统中的核心技术.高可用高可用集群,简单的说,集群就是一组计算机,它们作为一个整体向用户提供一组网络资源. 高可用工作方式:主从方式 (非对称方式).双机双工方式(互备互援).集群工作方式(多服务器互备方式),那么我们由于现实条件限制,所以今天做的是双机双工又称双主,实现的是方法是使用keepalived这个开源软件! 首先,我们要先准备四台centos机器,其中两

[ Linux运维学习 ] 路径及实战项目合集

我们知道运维工程师(Operations)最基本的职责就是负责服务的稳定性并确保整个服务的高可用性,同时不断优化系统架构.提升部署效率.优化资源利用率,确保服务可以7*24H不间断地为用户提供服务. 如果你想从事Linux运维相关工作,那么你可以来实验楼,因为实验上有: [Linux运维技术路径]:一条学习路径,多个阶段.若干课程带你一步步成为Linux运维工程师: [Linux运维与Devops实战]:12周时间,带你0基础到运维工程师,涵盖Linux运维常用技术和DevOps相关技术: --

运维小知识之nginx---nginx配置Jboss集群负载均衡

codyl 2016-01-26 00:53:00 浏览385 评论0 负载均衡 转自 运维小知识之nginx---nginx配置Jboss集群负载均衡-博客-云栖社区-阿里云https://yq.aliyun.com/articles/17925 运维小知识之nginx---nginx配置Jboss集群负载均衡 背景 紧接着上一篇博客<运维小知识---CentOS6.5安装nginx配置nginx sticky>安装完成之后剩下的工作就是配置了,其实如果我们想要去做负载均衡session共享

《Linux运维架构师课程 - 门徒班》【招生中】

课程简介 阿良的课程内容主要以企业核心技术为讲解对象,避免过多在企业中很少用的技术,从而减少学习负担,这样就可以把精力主要花费在更重要的技术上, 而不像其他培训机构那样,讲很多高大上的技术名词,其中可能50%的知识在工作中都用不到,学员抓不住重点,时间长了就忘了.    所以,阿良的教学模式讲究是精益求精,"好钢用到刀刃上,只求精,不求多".    只要你肯学,阿良就肯教.帮助你掌握这门技能,成功就业,初学者月薪达到6000以上. 授课对象 ■ 计算机相关专业在校学生/应届生 ■ 网络

k8s v1.13.4 集群部署

部署环境 主机节点清单 服务器名 ip地址 etcd K8S server K8s node node01 172.16.50.111 Y Y node02 172.16.50.113 Y Y node03 172.16.50.115 Y Y node04 172.16.50.116 Y node05 172.16.50.118 Y node06 172.16.50.120 Y node07 172.16.50.128 Y 版本信息 Linux版本:CentOS 7.6.1810 内核版本:3.

Linux运维架构师课程介绍

课程体系:     RHCE(RedHat Certification Engineer): RH033(基础) RH133(系统管理) RH253(服务管理)     RHCA(Redhat Centification Architect): RH401 RH423(LDAP协议) RH442         RH436(集群和存储) RHS333     MySQL     NoSQL 工作岗位: 系统架构师:设计蓝图 系统工程师:系统上线 运维工程师:系统运维 DBA:数据库管理员 计算机

Linux运维架构师学习开篇——笔记

从毕业从事硬件失效分析方面工作近三年, 偏冷门的行业,一直在工厂产线,吸着产品线散发出的一道道气息,闲暇之余我也在思考难道我今后只能在工厂待一辈子吗?我的职业只能在生产线处理不良产品,我的未来就是作为一个硬件高级维修工吗?我想走出产品线,对未来的职业发展充满迷茫,内心思想一直在挣扎.马上奔三后该做什么,能做什么? 以前接触过Linux,但仅仅是复制粘贴指令,配置IP,最基本操作而已,没有接触到真正的技术,为了今后能有一技之长,有个明确的发展方向(云端),也为了能拿到一份不错的薪水,提高生活质量,

Kubernetes1.15.2集群部署并部署Metrics Server插件

环境信息: 操作系统 主机名 IP地址 CentOS 7.6 k8s-master 192.168.31.61 CentOS 7.6 k8s-node1 192.168.31.62 CentOS 7.6 k8s-node2 192.168.31.63 1. 安装要求 在开始之前,部署Kubernetes集群机器需要满足以下几个条件: 操作系统 CentOS7.x-86_x64 硬件配置:2GB或更多RAM,2个CPU或更多CPU,硬盘30GB或更多 集群中所有机器之间网络互通 可以访问外网,需要