centos7部署k8s(1master1node)
阅读原文时间:2023年07月09日阅读:1

〇.前言

就想多学学罢了

准备环境:

centos7 master 8GB 172.26.130.204

centos7 node 8GB 172.26.130.205

yum源就阿里源就好。。。

一.再前言

etcd:提供分布式数据存储的数据库吧,用于持久化存储k8s集群的配置和状态。

kube-apiserver:api service提供了httprest接口,是整个集群的入口,K8s其它组件之间不直接通信,而是通过API server通信的。

kube-scheduler:scheduler负责资源的调度。

kube-controller-manager:整个集群的管理控制中心,此组件里面是由多个控制器组成的,如:Replication Manager(管理ReplicationController 资源),ReplicaSet Controller,PersistentVolume controller。主要作用用来复制组件、追踪工作结点状态、处理失败结点

flannel:好像是用来支持网络通信的吧

kube-proxy:用来负载均衡网络流量

kubelet:用来管理node节点机上的容器

docker:运行项目镜像容器的组件

二.开始安装

1.1、安装epel-release源

yum -y install epel-release

1.2、所有机器关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

#查看防火墙状态
firewall-cmd --state

2.1、使用yum安装etcd、kubernetes-master

yum -y install etcd kubernetes-master

2.2、编辑:vi /etc/etcd/etcd.conf文件,修改结果如下:

#[Member]
...
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
...
...
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
...
...
ETCD_NAME="default"
...
...
#[Clustering]
#ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

2.3、配置:vi /etc/kubernetes/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://127.0.0.1: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,ResourceQuota"

2.4、启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动。

命令略

2.5、在etcd中定义flannel网络

etcdctl set /atomic.io/network/config '{"NETWORK":"172.17.0.0/16"}'

》》》》》》》》》》》》》》》》》以上master主机上的配置安装什么的都弄完了》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

3.1、在node机上172.26.130.205安装kubernetes Node和flannel组件应用

yum -y install flannel kubernetes-node

3.2、为flannel网络指定etcd服务,修改/etc/sysconfig/flanneld文件,配置结果如下:

# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://172.26.130.204:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"

3.3、修改:vi /etc/kubernetes/config文件,配置结果如下

###
# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
#   kube-apiserver.service
#   kube-controller-manager.service
#   kube-scheduler.service
#   kubelet.service
#   kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://172.26.130.204:8080"

3.4、修改node机的kubelet配置文件/etc/kubernetes/kubelet

###
# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"

# The port for the info server to serve on
KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=172.26.130.205"

# location of the api-server
KUBELET_API_SERVER="--api-servers=http://172.26.130.204:8080"

# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

# Add your own!
KUBELET_ARGS=""

3.5、node节点机上启动kube-proxy,kubelet,docker,flanneld等服务,并设置开机启动。

命令略

》》》》》》以上所有master主机,node节点机上的配置就完成了,接下来看看k8s集群是否搭建起来了》》》》》》》》》》》》》》》》》》》

在master主机上172.26.130.204执行如下命令,查看运行的node节点机器:

[root@fcphost ~]# kubectl get nodes
NAME             STATUS    AGE
172.26.130.205   Ready     31m