k8s搭建
K8s官方文档地址:https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/ 如果用云主机部署,一定要提前开启端口
1. 服务器规划
角色 |
IP |
组件 |
k8s-master1 |
192.168.31.63 |
kube-apiserver kube-controller-manager kube-scheduler etcd |
k8s-master2 |
192.168.31.64 |
kube-apiserver kube-controller-manager kube-scheduler |
k8s-node1 |
192.168.31.65 |
kubelet kube-proxy docker etcd |
k8s-node2 |
192.168.31.66 |
kubelet kube-proxy docker etcd |
Load Balancer(Master) |
192.168.31.61 192.168.31.60 (VIP) |
Nginx L4 |
Load Balancer(Backup) |
192.168.31.62 |
Nginx L4 |
1.系统初始化
修改主机名称:
hostnamectl set-hostname k8s-master1
关闭防火墙:
# systemctl stop firewalld
# systemctl disable firewalld
关闭selinux:
# setenforce 0 # 临时
# sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
关闭swap:
# swapoff -a # 临时
# vim /etc/fstab # 永久
同步系统时间:
# ntpdate time.windows.com
2.2 部署三个Etcd节点
TLS、etcd地址:
链接:https://pan.baidu.com/s/1kyC5KgsF5DB2fZK5UGPaQg
提取码:o101
# tar zxvf etcd.tar.gz
# cd etcd
# cp TLS/etcd/ssl/{ca,server,server-key}.pem ssl
分别拷贝到Etcd三个节点:
# scp –r etcd root@192.168.31.63:/opt
# scp etcd.service root@192.168.31.63:/usr/lib/systemd/system/
登录三个节点修改配置文件 名称和IP:
# vi /opt/etcd/cfg/etcd.conf
#[Member]
ETCD_NAME="etcd-1" 名称一定要替换
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.31.63:2380" 内网ip
ETCD_LISTEN_CLIENT_URLS="https://192.168.31.63:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.31.63:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.31.63:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.31.63:2380,etcd-2=https://192.168.31.64:2380,etcd-3=https://192.168.31.65:2380" 部署3个节点的内网ip
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new" 集群状态
# systemctl daemon-reload
# systemctl start etcd
# ps -ef|grep etcd 查看etcd进程
# systemctl enable etcd 设置开机启动
# tail /var/log/messages -f 查看系统日志
2.3 查看集群状态
# /opt/etcd/bin/etcdctl \
> --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem \
> --endpoints="https://192.168.31.63:2379,https://192.168.31.64:2379,https://192.168.31.65:2379" \ 部署3个节点的内网ip一定要替换
> cluster-health
如果出现下面字段,说明集群状态是健康的
member 37f20611ff3d9209 is healthy: got healthy result from https://192.168.31.63:2379
member b10f0bac3883a232 is healthy: got healthy result from https://192.168.31.64:2379
member b46624837acedac9 is healthy: got healthy result from https://192.168.31.65:2379
cluster is healthy
1.部署Master Node
1.1 生成apiserver证书
# cd TLS/k8s
修改请求文件中hosts字段包含所有etcd节点IP:
# vi server-csr.json
{
"CN": "kubernetes",
"hosts": [
"10.0.0.1",
"127.0.0.1",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster",
"kubernetes.default.svc.cluster.local",
"192.168.31.60", 你的内网ip
"192.168.31.61",
"192.168.31.62",
"192.168.31.63",
"192.168.31.64",
"192.168.31.65",
"192.168.31.66"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"ST": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
# ./generate_k8s_cert.sh
# ls *pem
ca-key.pem ca.pem kube-proxy-key.pem kube-proxy.pem server-key.pem server.pem
3.2 部署apiserver,controller-manager和scheduler
在Master节点完成以下操作。
二进制包下载地址:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.16.md#v1161
master安装包下载地址:链接:https://pan.baidu.com/s/1kyC5KgsF5DB2fZK5UGPaQg
提取码:o101
二进制文件位置:kubernetes/serverr/bin
# tar zxvf k8s-master.tar.gz
# cd kubernetes
# cp TLS/k8s/ssl/*.pem ssl
# cp –r kubernetes /opt
# cp kube-apiserver.service kube-controller-manager.service kube-scheduler.service /usr/lib/systemd/system
# cat /opt/kubernetes/cfg/kube-apiserver.conf
KUBE_APISERVER_OPTS="--logtostderr=false \
--v=2 \
--log-dir=/opt/kubernetes/logs \
--etcd-servers=https://192.168.31.63:2379,https://192.168.31.64:2379,https://192.168.31.65:2379 \ 替换etcd节点的内网ip
--bind-address=192.168.31.63 \ 替换master节点的ip
--secure-port=6443 \
--advertise-address=192.168.31.63 \ 替换master节点的ip
……
# systemctl start kube-apiserver
# systemctl start kube-controller-manager
# systemctl start kube-scheduler
# systemctl enable kube-apiserver
# systemctl enable kube-controller-manager
# systemctl enable kube-scheduler
# systemctl start kube-apiserver
# ls /opt/kubernetes/logs 查看日志
# less /opt/kubernetes/logs/kube-apiserver.INFO
# tail -f /opt/kubernetes/logs/kube-controller-manager.INFO
# for i in $(ls /opt/kubernetes/bin);do systemctl enable $i;done开机启动
# mv /opt/kubernetes/bin/kubectl /usr/local/bin/kubectl 移动到环境变量
# chmod a+x /usr/local/bin/kubect
# kubectl get cs查看组件状态
# 查看3个组件的进程 ps -ef|grep kube
3.3 启用TLS Bootstrapping
为kubelet TLS Bootstrapping 授权:
# cat /opt/kubernetes/cfg/token.csv
c47ffb939f5ca36231d9e3121a252940,kubelet-bootstrap,10001,"system:node-bootstrapper"
格式:token,用户,uid,用户组
给kubelet-bootstrap授权:
kubectl create clusterrolebinding kubelet-bootstrap \
--clusterrole=system:node-bootstrapper \
--user=kubelet-bootstrap
token也可自行生成替换:
head -c 16 /dev/urandom | od -An -t x | tr -d ' '
但apiserver配置的token必须要与node节点bootstrap.kubeconfig配置里一致。
1.部署Worker Node
1.1 安装Docker
二进制包下载地址:https://download.docker.com/linux/static/stable/x86_64/
docker下载地址: 链接:https://pan.baidu.com/s/1kyC5KgsF5DB2fZK5UGPaQg
提取码:o101
# tar zxvf k8s-node.tar.gz
# tar zxvf docker-18.09.6.tgz
# mv docker/* /usr/bin
# mkdir /etc/docker
# mv daemon.json /etc/docker
# mv docker.service /usr/lib/systemd/system
# systemctl start docker
# systemctl enable docker
# docker info 通过docker info查看docker是否启动成功
执行docker info出现如下警告
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
解决办法:
vi /etc/sysctl.conf
添加以下内容
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
最后再执行
sysctl -p
此时docker info就看不到此报错了
执行docker info出现如下警告
4.2 部署kubelet和kube-proxy
拷贝证书到Node:
# cd TLS/k8s
# scp ca.pem kube-proxy*.pem root@192.168.31.65:/opt/kubernetes/ssl/
# cp kube-apiserver.service kube-controller-manager.service kube-
# tar zxvf k8s-node.tar.gz
# mv kubernetes /opt
# cp kubelet.service kube-proxy.service /usr/lib/systemd/system
查看以下三个文件中IP地址:
[root@k8s-node2 kubernetes]# grep 192 *
修改以下两个文件中主机名:
[root@k8s-node2 cfg]# vim bootstrap.kubeconfig
[root@k8s-node2 cfg]# vim kubelet.conf
[root@k8s-node2 cfg]# vim kubelet.kubeconfig
[root@k8s-node2 cfg]# vim kube-proxy-config.yml
[root@k8s-node2 cfg]# vim kube-proxy.kubeconfig
# systemctl start kubelet
# systemctl start kube-proxy
# systemctl enable kubelet
# systemctl enable kube-proxy
# tail /opt/kubernetes/logs/kubelet.INFO 查看日志
4.3 允许给Node颁发证书
# kubectl get csr
# kubectl certificate approve node-csr-MYUxbmf_nmPQjmH3LkbZRL2uTO-_FCzDQUoUfTy7YjI 替换你的node名称
# kubectl get node
k8s搭建的更多相关文章
- k8S 搭建集群
k8S 搭建集群1:修改主机名称hostnamectl --static set-hostname masterhostnamectl --static set-hostname node1hostn ...
- 阿里云手动搭建k8s搭建中遇到的问题解决(持续更新)
ETCD搭建 systemd启动etcd服务的时候出现错误:Failed at step CHDIR spawning /usr/bin/etcd: No such file or directory ...
- k8s搭建rook-ceph
一.介绍 Rook官网:https://rook.io Rook是云原生计算基金会(CNCF)的孵化级项目. Rook是Kubernetes的开源云本地存储协调器,为各种存储解决方案提供平台,框架和支 ...
- K8S搭建-1 Master 2 Workers(dashboard+ingress)
本文讲述k8s最新版的搭建(v1.15.2) 分如下几个topic步骤: 各个节点的基本配置 master节点的构建 worker节点的构建 安装dashboard 安装ingress 常见命令 do ...
- K8S 搭建 Kafka:2.13-2.6.0 和 Zookeeper:3.6.2 集群
搭建 Kafka:2.13-2.6.0 和 Zookeeper:3.6.2 集群 一.服务版本信息: Kafka:v2.13-2.6.0 Zookeeper:v3.6.2 Kubernetes:v1. ...
- iot平台在k8s搭建过程
统一在 cd /opt/iot nohup /opt/iopservices.sh >/var/log/helmapi.log & 直接查看pod日志? kubectl logs i ...
- rancher1.X+docker+k8s搭建容器管理集群
一, 环境准备 服务器 Linux k8s-m -.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Li ...
- k8s搭建WebUI--Dashborad管理界面
k8s的webUI管理界面可以更好更直观更便捷的让我们去管理我们的k8s集群. 我们知道,由于某些原因我们无法直接拉取dashboard的镜像,但是国内有些人已经将镜像下载到dockerhub中可以给 ...
- K8S搭建过程随笔_系统初始化
组件 Kubernetes 1.14.2 Docker 18.09.6-ce Etcd 3.3.13 Flanneld 0.11.0 基础环境设置 192.168.11.188 k8s-master ...
- K8S搭建过程随笔_证书CFSSL
安装CFSSL mkdir -p /opt/k8s/cert && cd /opt/k8swget https://pkg.cfssl.org/R1.2/cfssl_linux-amd ...
随机推荐
- HTML代码中<%%>、<%=%>
运行.获取后台代码或值.<%%>之间可以写服务器端代码,比如<%for(var i=0;i<10;i++){//执行循环体}%>又如<%for(var i=0;i& ...
- maven scope 的作用
一: 1.Maven中的依赖作用范围概述 Maven中使用 scope 来指定当前包的依赖范围和依赖的传递性.常见的可选值有:compile, provided, runtime, test, sys ...
- Suggestions On Setting LED Holiday Light
We all like the cheerful glow of holiday lights, so the process goes seamless from start to finish. ...
- Centos7 入门几个操作
http://www.wallcopper.com/linux/1650.html 创建文件软连接 ln -s 源路径 目标路径 查看软连接ls -il 服务操作:systemctl start fo ...
- Win系统如何修改远程桌面端口3389
Win系统如何修改远程桌面端口3389: https://jingyan.baidu.com/article/ce43664928d5293773afd39b.html window10远程桌面连接: ...
- ASPxDashboardViewer_OnDashboardLoaded 修改Item参数
protected void ASPxDashboardViewer_OnDashboardLoaded(object sender, DashboardLoadedWebEventArgs e) { ...
- C++ windows线程操作(转)
参考 1._beginthreadex创建线程 DWORD m_dwMSGTID; // 线程ID HANDLE m_hMSG; // 线程句柄 m_hMSG = (HANDLE)_beginthre ...
- python:函数中的*args与**kwargs
首先定义一个包含*args和**kwargs的函数,这个函数唯一的功能就是输出自己的两个参数,以此来理解*args和**kwargs def myFunc(*args, **kwargs): prin ...
- hfs 文件存储
hfs 服务器上面的和本地拖上去的文件是同一个文件.对本地文件拖上去之后再修改,服务器文件也会修改.所以服务器要有一个自己的文件存放.
- Pikachu练习平台(暴力破解)
Pikachu练习平台(暴力破解) 因为下面要用到burp suite,这里先简单介绍一下intruder模块的东西 Target选项: 设置攻击目标,可以通过proxy发送 Pasit ...