是不会方式多种多样

MicroK8s部署

MicroK8s适合单机测试环境,友好的操作体验可以很轻松的上手k8s集群控制和开发。

// MicroK8s 依赖 snapd工具需要第一个安装
sudo yum install epel-release
sudo yum install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
//通过snap工具安装microk8s
sudo snap install microk8s --classic
snap info microk8s
// 启动集群
sudo microk8s.start
//停止集群
sudo microk8s.stop
//查看所有容器启动情况
microk8s.kubectl get all --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default pod/nginx-7db9fccd9b-7klhs 0/1 ContainerCreating 0 76m
default pod/nginx-7db9fccd9b-8zjwg 0/1 ContainerCreating 0 7
//查看当前集群的编号和版本
[root@k8smaster ~]# microk8s.kubectl get no
NAME STATUS ROLES AGE VERSION
k8smaster Ready <none> 109m v1.14.0
//监控当前所有容器工作状态
watch microk8s.kubectl get all --all-namespaces

//删除容器
microk8s.kubectl delete deployment/nginx
deployment.extensions "nginx" deleted

以安装包的方式直接搭建

etcd服务

etcd 服务是作为k8s集群的主数据库,用来存放所有的容器状态的主数据库。

// 安装etcd
yum install etcd
// etcd配置文件, 默认监听在2379号端口
vi /etc/etcd/etcd.conf
//指定数据存放位置
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
//指定该节点名称
ETCD_NAME="master"
//指定客户端监听url,对外提供服务的地址
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379"
//对外公告该客户端监听地址
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"
// 启动服务
systemctl daemon-reload
// 启动服务
systemctl enable etcd.service
systemctl start etcd.service
//验证etcd健康状态
etcdctl -C http://localhost:2379 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://localhost:2379
cluster is healthy

k8s Mster 相关服务安装

接下来将是我们非常重要的服务,k8s它有三个主要的服务:

  1. kube-apiserver服务
  2. kube-kube-controller-manager服务,依赖apiserver
  3. kube-scheduler服务,依赖apiserver
//三个服务都已经集成到kubernetes中了
yum install kubernetes -y
//配置kube-apiserver
vi /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_API_ARGS="
--insecure-port=8000
--service-cluster-ip-range=169.169.0.0/16
--service-node-port-range=1-65535
-logtostderr=false
--log-dir=/var/log/kubernetes
-v=2
"
//配置kube-controller-manager
vi /etc/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS="
--master=http://127.0.0.1:8000
--logtostderr=false
--v=2
"
//配置kube-scheduler
vi /etc/kubernetes/scheduler
KUBE_SCHEDULER_ARGS="
-master=http://127.0.0.1:8000
--logtostderr=false
--log-dir=/var/log/kubernetes
--v=2
"
//k8s配置config
vi /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://127.0.0.1:8000"
//启动k8s各个组件
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
//加入到系统服务中
systemctl enable kube-apiserver.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-apiserver.service to /usr/lib/systemd/system/kube-apiserver.service.
systemctl enable kube-controller-manager.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to /usr/lib/systemd/system/kube-controller-manager.service.
systemctl enable kube-scheduler.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-scheduler.service to /usr/lib/systemd/system/kube-scheduler.service.

k8s Worker服务搭建

//安装服务
yum install kubernetes -y
//k8s配置
vi /etc/kubernetes/config
//指定master地址位置
KUBE_MASTER="--master=http://127.0.0.1:8000"
//启动服务
systemctl enable kubelet.service
systemctl enable kube-proxy.service
//配置master节点地址
export KUBERNETES_MASTER=http://centos-master:8080