CentOS7.6部署k8s环境
CentOS7.6部署k8s环境
测试环境:
|
节点名称 |
节点IP |
节点功能 |
|
K8s-master |
10.10.1.10/24 |
Master、etcd、registry |
|
K8s-node-1 |
10.10.1.20/24 |
node-1 |
|
K8s-node-2 |
10.10.1.30/24 |
node-2 |
步骤:
- 修改hosts文件
[root@Node-1 ~]# hostnamectl --static set-hostname k8s-master
[root@Node-1 ~]# vi /etc/hosts
10.10.1.10 k8s-master
10.10.1.10 etcd
10.10.1.10 registry
10.10.1.20 k8s-node-1
10.10.1.30 k8s-node-2
- 部署etcd(注:本次只master节点安装etcd)
[root@node-1 ~]# yum install etcd –y
[root@node-1 ~]# vi /etc/etcd/etcd.conf
#[Member]
#ETCD_CORS=""
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_LISTEN_PEER_URLS="http://localhost:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
ETCD_NAME="master"
#[Clustering]
#ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380"
ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379,http://etcd:4001
启动服务
[root@node-1 ~]# systemctl start etcd.service
[root@node-1 ~]# systemctl enable etcd.service
验证集群状态
[root@node-1 ~]# etcdctl -C http://etcd:4001 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://etcd:2379
cluster is healthy
[root@node-1 ~]#
- 部署master
3.1.安裝docker
[root@node-1 ~]# yum install docker
[root@node-1 ~]# vi /etc/sysconfig/docker
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
OPTIONS='--insecure-registry registry:5000'
3.2.启动docker服务并设置开机启动
[root@node-1 ~]# systemctl start docker.service
[root@node-1 ~]# systemctl enable docker.service
3.3.安裝kubernets
[root@node-1 ~]# yum install kubernetes
3.4. 配置并且启动kubernets服务(该步骤只在master节点)
Kubernets API Server
Kubernets Controller Manager
Kubernets Scheduler
[root@node-1 ~]# vi /etc/kubernetes/apiserver
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#
# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"
# Port minions listen on
# KUBELET_PORT="--kubelet-port=10250"
# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://etcd:2379"
# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
# default admission control policies
#KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
# Add your own!
KUBE_API_ARGS=""
[root@node-1 ~]# vi /etc/kubernetes/config
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://k8s-master:8080"
3.5. 启动服务并设置开机启动
[root@k8s-master ~]# systemctl enable kube-apiserver.service
[root@k8s-master ~]# systemctl start kube-apiserver.service
[root@k8s-master ~]# systemctl enable kube-controller-manager.service
[root@k8s-master ~]# systemctl start kube-controller-manager.service
[root@k8s-master ~]# systemctl enable kube-scheduler.service
[root@k8s-master ~]# systemctl start kube-scheduler.service
- 部署节点
4.1.部署和3.1-3.3相同
4.2.修改配置文件
[root@Node-2 ~]# vi /etc/kubernetes/config
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://k8s-master:8080"
[root@Node-2 ~]# vi //etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=k8s-node-1"
KUBELET_API_SERVER="--api-servers=http://etcd:8080"
4.3.启动服务并设置开机启动
[root@k8s-node-1 ~]# systemctl enable kubelet.service
[root@k8s-node-1 ~]# systemctl start kubelet.service
[root@k8s-node-1 ~]# systemctl enable kube-proxy.service
[root@k8s-node-1~]# systemctl start kube-proxy.service
- 查看群集状态
[root@k8s-master ~]# kubectl get node
NAME STATUS AGE
k8s-node-1 Ready 14h
k8s-node-2 Ready 14h
- 安装Flannel(所有节点)
[root@node-1 ~]# yum install flannel
[root@node-1 ~]# vi /etc/sysconfig/flannel
# Flanneld configuration options
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"
- 配置etcd中关于flannel的key
[root@node-1 ~]# etcdctl mk /atomic.io/network/config '{ "Network": "10.0.0.0/16" }'
设置flannel服务启动和开机启动:
[root@node-1 ~]# systemctl enable flanneld.service
[root@node-1 ~]# systemctl start flanneld.serivice
管理节点执行:
service docker restart
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service
业务节点执行
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service
业务节点拉取image
[root@Node-2 ~]# docker pull winstonpro/lnmp
[root@Node-2 ~]# docker pull tomcat
[root@Node-2 ~]# docker pull httpd
管理节点创建实例
kubectl run web --image=winstonpro/lnmp --port=80
管理节点做svc映射
kubectl expose deployment web --port=80 --target-port=80 --external-ip=10.10.1.30
常用命令:
[root@node-1 ~]# kubectl get node -o wide
NAME STATUS AGE EXTERNAL-IP
k8s-node-1 Ready 14h <none>
k8s-node-2 Ready 14h <none>
[root@node-1 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
app-556711052-ps9kr 1/1 Running 3 7h 10.0.53.2 k8s-node-1
tomcat-3343039334-0z187 1/1 Running 0 2h 10.0.74.3 k8s-node-2
web-3818241055-g11q8 1/1 Running 3 8h 10.0.74.2 k8s-node-2
[root@node-1 ~]# kubectl get svc -o wide
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes 10.254.0.1 <none> 443/TCP 15h <none>
tomcat 10.254.69.86 10.10.1.30 7777/TCP 2h run=tomcat
web 10.254.76.251 10.10.1.30 80/TCP 6h run=web
[root@node-1 ~]# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app 1 1 1 1 7h
tomcat 1 1 1 1 2h
web 1 1 1 1 8h
关于外网无法访问:
[root@Node-2 ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@Node-2 ~]# sysctl -p
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
CentOS7.6部署k8s环境的更多相关文章
- Centos7.6部署k8s v1.16.4高可用集群(主备模式)
一.部署环境 主机列表: 主机名 Centos版本 ip docker version flannel version Keepalived version 主机配置 备注 master01 7.6. ...
- CentOS7.6部署ceph环境
CentOS7.6部署ceph环境 测试环境: 节点名称 节点IP 磁盘 节点功能 Node-1 10.10.1.10/24 /dev/sdb 监控节点 Node-2 10.10.1.20/24 /d ...
- django2.0 + python3.6 在centos7 下部署生产环境的一些注意事项
一:mysql 与环境选用的坑 目前, 在生产环境部署django有三种方式: 1. apache + mod_wsgi 2. nginx + uwsigi 3. nginx + supervisor ...
- centos7.2 部署k8s集群
一.背景 二.使用范围 ♦ 测试环境及实验环境 三.安装前说明 ♦ k8s网络基本概念 ♦ 集群规划图 ♦ 软件版本选取 Name Version Description docker-ce 18. ...
- centos7下部署iptables环境纪录(关闭默认的firewalle)
CentOS7默认的防火墙不是iptables,而是firewall.由于习惯了用iptables作为防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables ...
- centos7下部署iptables环境纪录(关闭默认的firewalle)(转)
下面介绍centos7关闭firewall安装iptables,并且开启80端口.3306端口的操作记录:[root@localhost ~]# cat /etc/redhat-release Cen ...
- CentOS7单机部署lamp环境和apache虚拟主机
(1)apache介绍 apache : httpd.apache.org 软件包:httpd 端口服务:80/tcp(http) 443/tcp(https,http+ssl) 配置文件: /etc ...
- centos7.1部署java环境服务器
1.检查操作系统自带java是jdk还是jre(否有javac,本例中没有javac) [root@bogon ~]# ls -l /usr/lib/jvm/总用量 0drwxr-xr-x. 3 ro ...
- ansible一键部署k8s单机环境
一.虚拟机准备 干净的Centsot7.4.4G内存.2个CPU 最小化安装,最好带虚拟化 二.执行初始化脚本 注意:脚本中配置静态网卡根据实际网卡名称配置,我用的是ens33 可以用 sed -i ...
随机推荐
- spring boot 2.X上传文件限制大小
Spring Boot 1.3.x multipart.maxFileSize multipart.maxRequestSize Spring Boot 1.4.x and 1.5.x spring. ...
- 《mysql必知必会》笔记1(检索、排序、过滤、计算、汇聚、分组)
一:了解SQL 1:列是表中的字段,所有表都由一个或多个列组成的.行是表中的记录,表中的数据都按行存储. 2:表中每一行都应该有可以唯一标识自己的一列或一组列.主键(一列或一组列),其值能够唯一区分每 ...
- dataframe添加元素指定为列表,不同for循环命名空间下的变量重复问题
split=pd.DataFrame({'data':[0],'len':0,'count':0},index=[0])for i_t in range(over_128.shape[0]): ct= ...
- LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给定值,求满足欧拉值大于等于这个 ...
- Python深入:修改Python搜索路径
当Python执行import语句时,它会在一些路径中搜索Python模块和扩展模块.可以通过sys.path查看这些路径,比如: >>> import sys >>&g ...
- 安装visualStudio 出现 cant install Microsoft.TeamFoundation.OfficeIntegration.Resources
本文告诉大家在安装 VisualStudio 时出现cant install Microsoft.TeamFoundation.OfficeIntegration.Resources如何安装 如果在安 ...
- C++ 结构体的定义
struct 结构体名称{ 数据类型 A: 数据类型 B; }结构体变量名; 相当于: struct 结构体名称{ 数据类型 A: 数据类型 B; }; struct 结构体名 ...
- 洛谷P5664 Emiya 家今天的饭 问题分析
首先来看一道我编的题: 安娜写宋词 题目背景 洛谷P5664 Emiya 家今天的饭[民间数据] 的简化版本. 题目描述 安娜准备去参加宋词大赛,她一共掌握 \(n\) 个 词牌名 ,并且她的宋词总共 ...
- hdu 4063 Aircraft (Geometry + SP)
Problem - 4063 几何加简单最短路. 题意是给出若干圆的圆心以及半径,求出从给出的起点到终点的最短路径的长度,可以移动的区域是圆覆盖到的任意一个位置. 做法是这样的,对圆两两求交点,用这些 ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...