Centos搭建kubenetes集群

简介: 本文描述在阿里云ECS中,自建kubeneters集群。

准备

  • 至少2台机器,1台作为master,其他机器作为node
  • 机器最低配置:2cpu,2g内存

安装docker

配置docker安装包下载源

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

下载和安装docker

 sudo yum install docker-ce docker-ce-cli containerd.io

配置docker镜像下载加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gvfjy25r.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

下载kubeadm,kubectl,kubelet安装包

配置安装源

创建/etc/yum.repos.d/kubernetes.repo文件

/etc/yum.repos.d/kubernetes.repo

文件中添加如下内容

[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

安装

yum install -y kubelet kubeadm kubectl

搭建kubenetes集群

检查需要安装镜像

kubeadm config images list

启动kubeneters cluster

kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers

option介绍

--image-repository Choose a container registry to pull control plane images from (default "k8s.gcr.io")

--pod-network-cidr Specify range of IP addresses for the pod network. If set, the control plane will automatically allocate CIDRs for every node.

执行上述命令后,可以看到如下信息

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.16.158.50:6443 --token q3dg40.lr0suvqa23s0h3if \
    --discovery-token-ca-cert-hash sha256:ffe2ec1194c6a6acfc2bb46ccb37a8d5e129aa26812b68c2a81f19be98f5a313
    

安装kube-flannel插件

保证pod之间可以通信

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml

也可以将kube-flannel.yml下载(wget工具)到本地,然后再用kubectl apply启动。

node加入集群

节点加入集群

命令:

kubeadm join 172.16.158.50:6443 --token q3dg40.lr0suvqa23s0h3if \
    --discovery-token-ca-cert-hash sha256:ffe2ec1194c6a6acfc2bb46ccb37a8d5e129aa26812b68c2a81f19be98f5a313

在同一个账号下同一个区域内,会收到如下信息:

[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

查看节点运行情况

kubectl get nodes --all-namespace
NAME                      STATUS   ROLES    AGE   VERSION
izbp17m6hlxv4d1w6eelqoz   Ready    <none>   42h   v1.17.3
izbp1htc4i0js572re75azz   Ready    master   47h   v1.17.3
相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务&nbsp;ACK 容器服务&nbsp;Kubernetes&nbsp;版(简称&nbsp;ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
目录
相关文章
|
7月前
|
Kubernetes Linux Docker
百度搜索:蓝易云【CentOS7系统规划搭建 kubernetes 集群详细教程。】
现在,你已经成功规划和搭建了一个基于CentOS 7的Kubernetes集群。你可以使用kubectl命令管理和部署应用程序到集群中。根据需求,你还可以配置和调优集群的各项参数和插件,以满足特定的应用需求。
174 0
|
4月前
|
消息中间件 Kafka Linux
Apache Kafka-初体验Kafka(03)-Centos7下搭建kafka集群
Apache Kafka-初体验Kafka(03)-Centos7下搭建kafka集群
70 0
|
14天前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
28天前
|
存储 分布式计算 资源调度
centos 部署Hadoop-3.0-高性能集群(二)
centos 部署Hadoop-3.0-高性能集群(二)
20 0
centos 部署Hadoop-3.0-高性能集群(二)
|
28天前
|
分布式计算 Hadoop Java
centos 部署Hadoop-3.0-高性能集群(一)安装
centos 部署Hadoop-3.0-高性能集群(一)安装
24 0
|
1月前
|
Kubernetes 应用服务中间件 网络安全
CentOS7上二进制部署Kubernetes高可用集群(v1.18版本)
CentOS7上二进制部署Kubernetes高可用集群(v1.18版本)
134 0
|
2月前
|
Kubernetes 关系型数据库 Linux
linux安装centos7 kubenetes 单机版安装k8s
linux安装centos7 kubenetes 单机版安装k8s
47 0
|
3月前
|
Java Linux 开发工具
Centos7搭建minio分布式集群
Centos7搭建minio分布式集群
|
5月前
|
存储 Kubernetes Cloud Native
云原生|kubernetes|centos7下的kubeadm部署的集群内在线部署kubesphere(外部etcd)
云原生|kubernetes|centos7下的kubeadm部署的集群内在线部署kubesphere(外部etcd)
71 0
|
5月前
|
Kubernetes Cloud Native Linux
云原生|kubernetes|kubeadm五分钟内部署完成集群(完全离线部署---适用于centos7全系列)
云原生|kubernetes|kubeadm五分钟内部署完成集群(完全离线部署---适用于centos7全系列)
65 0

热门文章

最新文章