k8s集群的简单搭建

K8S简单集群搭建

前提条件

  • windos11电脑,内存16g以上
  • 安装vmware虚拟机软件
  • 安装三个centos7虚拟机,分配硬盘40g,内存4g,CPU4核心
  • 网络均采用NAT模式(新建虚拟机默认的模式)

centos7镜像下载:https://mirrors.tuna.tsinghua.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-2207-02.iso

我电脑上三个centos7虚拟机均采用最小化安装,IP如下:

名称IP地址
k8s-master1192.169.94.132
k8s-node1192.168.94.133
k8s-node2192.168.94.134

其中硬盘分配:

  • /boot 1024M
  • swap 2048M
  • / 37G

系统准备

如下命令,没有特殊说明,则在三个节点上都要执行一次

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

关闭selinux

sed -i 's/enforcing/disabled/' /etc/selinux/config  # 永久
setenforce 0  # 临时

关闭swap

swapoff -a  # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab    # 永久

设置主机名

  • 在master虚拟机上执行

    hostnamectl set-hostname k8s-master1
    
  • 在node1虚拟机上执行

    hostnamectl set-hostname k8s-node1
    
  • 在node2虚拟机上执行

    hostnamectl set-hostname k8s-node2
    

添加hosts

在master虚拟机上执行

cat >> /etc/hosts << EOF
192.168.94.132 k8s-master1
192.168.94.133 k8s-node1
192.168.94.134 k8s-node2
EOF

将桥接的IPv4流量传递到iptables的链

cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

生效:

sysctl --system

时间同步

yum install ntpdate -y
ntpdate time.windows.com

可能的问题

  • 无法使用ifconfig 命令

    需要安装net-tools:

     yum install net-tools
    

k8s安装

k8s的默认容器运行时(CRI)为docker,因此要先安装docker

docker安装

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repoyum -y install docker-ce-18.06.1.ce-3.el7systemctl enable docker && systemctl start docker

验证docker是否安装好:

docker --version

如果下方出现了docker的版本,则说明安装没问题。

设置docker的镜像拉取地址:

cat > /etc/docker/daemon.json << EOF
{"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF

kubeadm/kubelet/kubectl的安装

设置k8s的软件源
$ cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 
EOF
安装

注意:最好是指定版本,因为坑已踩过

$ yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
$ systemctl enable kubelet
初始化Master

在master1上执行集群的master节点初始化:(指定阿里云镜像仓库)

kubeadm init \--apiserver-advertise-address=192.168.94.132 \--image-repository registry.aliyuncs.com/google_containers \--kubernetes-version v1.18.0 \--service-cidr=10.96.0.0/12 \--pod-network-cidr=10.244.0.0/16

执行这句话之后,控制台输出如下:

[root@localhost ~]# kubeadm init \
>   --apiserver-advertise-address=192.168.94.132 \
>   --image-repository registry.aliyuncs.com/google_containers \
>   --kubernetes-version v1.18.0 \
>   --service-cidr=10.96.0.0/12 \
>   --pod-network-cidr=10.244.0.0/16
W1004 11:44:59.317714   70492 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.18.0
[preflight] Running pre-flight checks[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8s-master1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.94.132]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master1 localhost] and IPs [192.168.94.132 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master1 localhost] and IPs [192.168.94.132 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
W1004 11:45:44.142408   70492 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[control-plane] Creating static Pod manifest for "kube-scheduler"
W1004 11:45:44.143008   70492 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 14.503883 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.18" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8s-master1 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node k8s-master1 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: t6p6ko.ok8x7h1era4pq66e
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxyYour Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configYou 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 192.168.94.132:6443 --token t6p6ko.ok8x7h1era4pq66e \--discovery-token-ca-cert-hash sha256:c1b3fd084dac33494a27532c368c844181e6942c5c0d2007c2e683ac3ffea83a 

注意最后这一句,这是初始化master几点生成的node加入时使用的token,默认为24小时,后面会用到

kubeadm join 192.168.94.132:6443 --token t6p6ko.ok8x7h1era4pq66e \--discovery-token-ca-cert-hash sha256:c1b3fd084dac33494a27532c368c844181e6942c5c0d2007c2e683ac3ffea83a

当token过期后,想其他的node节点加入,可通过如下命令重新创建token:

kubeadm token create --print-join-command
部署CNI网络插件

在master节点上执行(下载yml文件):

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

在master节点上应用文件:

kubectl apply -f kube-fannel.yml

可能出现问题:拉取yml文件失败:

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
--2023-10-04 11:50:46--  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... ::1, 127.0.0.1
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|::1|:443... 失败:拒绝连接。
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|127.0.0.1|:443... 失败:拒绝连接。

解决办法:参考wget安装flannel插件-连接失败_Geray-zsg的博客-CSDN博客

/etc/hosts 文件中添加如下解析:

199.232.68.133 raw.githubusercontent.com

再执行就可以正常下载了

k8s安装后测试

在k8s集群中创建一个pod:

kubectl create deployment nginx --image=nginx

暴露端口:

kubectl expose deployment nginx --port=80 --type=NodePort

查看暴露的服务:

[root@localhost etc]# kubectl get pod,svc
NAME                        READY   STATUS    RESTARTS   AGE
pod/nginx-f89759699-hnhl9   1/1     Running   0          59mNAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        67m
service/nginx        NodePort    10.96.178.17   <none>        80:32377/TCP   46m

验证访问:

http://192.168.94.132:32377

http://192.168.94.133:32377

http://192.168.94.134:32377

如果都能访问,代表k8s集群部署正常

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/149033.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

QT4.8.7安装详细教程

QT4.8.7安装详细教程&#xff08;MinGW 4.8.2和QTCreator4.2.0&#xff09; 1.下载及安装2.配置环境 此文是在下方链接博文的基础上&#xff0c;按自己的理解整理的https://blog.csdn.net/xiaowanzi199009/article/details/104119265 1.下载及安装 这三个文件&#xff0c;顺序是…

Swift SwiftUI CoreData 过滤数据 1

Xcode: Version 14.3.1 (14E300c) iOS: 16 预览&#xff1a; Code: import SwiftUI import CoreDatastruct TodosSearch: View {State private var search_title "测试"FetchRequest var todos_search: FetchedResults<Todo>init() {let request: NSFetchReq…

Cortex-A9 架构

一、Cortex-A 处理器运行模式 Cortex-A9处理器有 9中处理模式&#xff0c;如下表所示&#xff1a; 九种运行模式 在上表中&#xff0c;除了User(USR)用户模式以外&#xff0c;其它8种运行模式都是特权模式&#xff0c;在特权模式下&#xff0c;程序可以访问所有的系统资源。这…

在openwrt dnsmasq DHCP中为客户端分配不同的网关和DNS | 旁路由 禁止上网

环境&#xff1a;openwrt dnsmasq PS4/Switch 问题&#xff1a;为路由器下的设备分配不同的网关和DNS&#xff0c;禁止局域网设备上网 解决办法&#xff1a;修改dnsmasq配置文件 背景&#xff1a;Openwrt 的DHCP服务是使用dnsmasq实现的&#xff0c;他可以给内网的客户端设备…

网络安全工程师考证指南,不看就亏了!!

目前网络安全行业&#xff0c;国内都有哪些证书可以考&#xff1f; 一、CISP-PTE &#xff08;国家注册渗透测试工程师&#xff09; CISP-PTE即注册信息安全渗透测试工程师&#xff0c;该证书由中国信息安全测评中心颁发&#xff0c;证书是国内唯一认可的渗透测试认证&#x…

el-menu 导航栏学习(1)

最简单的导航栏学习跳转实例效果&#xff1a; &#xff08;1&#xff09;index.js路由配置&#xff1a; import Vue from vue import Router from vue-router import NavMenuDemo from /components/NavMenuDemo import test1 from /components/test1 import test2 from /c…

Redis中Hash类的操作

Redis中Hash类型是键值对的形式保存数据&#xff0c;其中键被称为字段&#xff08;field&#xff09;&#xff0c;值称为字段值&#xff08;value&#xff09;。在一个key中&#xff0c;字段不能重复&#xff0c;而值可以重复。无论是字段还是值都是无序的&#xff08;保存的次…

mysql双主+双从集群连接模式

架构图&#xff1a; 详细内容参考&#xff1a; 结果展示&#xff1a; 178.119.30.14(主) 178.119.30.15(主) 178.119.30.16(从) 178.119.30.17(从)

添加驱动模块到内核的两种方法

添加驱动模块到内核的两种方法 1. 放在内核源代码树中 步骤总结&#xff1a; 新建文件夹编写Makefile、编写Kconfig修改上层Kconfig执行make menuconfig执行make zImage 或 make modules 1.1 源码放入文件夹 例如&#xff1a;添加一个按键字符设备模块 在内核目录下的 dri…

【推荐系统】多任务学习模型

介绍一些多任务学习模型了解是如何处理多任务分支的。 ESSM, Entire Space Multi-Task Model 阿里提出的ESSM全称Entire Space Multi-Task Model&#xff0c;全样本空间的多任务模型&#xff0c;有效地解决了CVR建模&#xff08;转化率预估&#xff09;中存在的两个非常重要…

MATLAB中plot3函数用法

目录 语法 说明 向量和矩阵数据 表数据 其他选项 示例 绘制三维螺旋图 绘制多个线条 使用矩阵绘制多个线条 指定等间距刻度单位和轴标签 将点绘制为不带线的标记 自定义颜色和标记 指定线型 在绘图后修改线条 绘制表中的数据 在 x 和 y 轴上绘制多个表变量 指…

10.2 调试事件获取DLL装载

理解了如何通过调试事件输出当前进程中寄存器信息&#xff0c;那么实现加载DLL模块也会变得很容易实现&#xff0c;加载DLL模块主要使用LOAD_DLL_DEBUG_EVENT这个通知事件&#xff0c;该事件可检测进程加载的模块信息&#xff0c;一旦有新模块被加载或装入那么则会触发一个通知…

Qt扫盲-QSqlTableModel理论总结

QSqlTableModel理论总结 一、概述二、使用1. 与 view 视图绑定2. 做中间层&#xff0c;不显示 三、常用函数 一、概述 QSqlTableModel是用于从单个表读写数据库记录的高级接口。它构建在较低级的QSqlQuery之上&#xff0c;可用于向QTableView 等视图类提供数据。这个主要是对单…

苹果V3签名是什么?优势是什么?什么场合需要应用到?该怎么部署?

v3签名&#xff0c;或称为Apple Developer Program v3签名&#xff0c;是苹果公司在2021年6月推出的一种签名格式&#xff0c;用于对应用程序进行签名和验证。 它是取代了之前的v2签名格式&#xff0c;用于增强应用程序的安全性和完整性。 v3签名能够做到以下几点&#xff1a;…

【Linux基础】Linux发展史

&#x1f449;系列专栏&#xff1a;【Linux基础】 &#x1f648;个人主页&#xff1a;sunny-ll 一、前言 本篇主要介绍Linux的发展历史&#xff0c;这里并不需要我们掌握&#xff0c;但是作为一个合格的Linux学习者与操作者&#xff0c;这些东西是需要了解的&#xff0c;而且…

前端JavaScript入门到精通,javascript核心进阶ES6语法、API、js高级等基础知识和实战 —— Web APIs(五)

思维导图 Bom操作 一、Window对象 1.1 BOM(浏览器对象模型) <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"vi…

k8s集群-6(daemonset job cronjob控制器)

Daemonset 一个节点部署一个节点 当有节点DaemonSet 确保全部 (或者某些) 节点上运行一个 Pod 的副本。加入集群时&#xff0c;也会为他们新增一个 Pod 。当有节点从集群移除时&#xff0c;这些Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod。 DaemonSet 的典型用…

Boost程序库完全开发指南:1.1-C++基础知识点梳理

主要整理了N多年前&#xff08;2010年&#xff09;学习C的时候开始总结的知识点&#xff0c;好长时间不写C代码了&#xff0c;现在LLM量化和推理需要重新学习C编程&#xff0c;看来出来混迟早要还的。 1.shared_ptr 解析&#xff1a;shared_ptr是一种计数指针&#xff0c;当引…

数字电路逻辑与设计 之循环码和 移存码

有发现错误的能力&#xff0c;不能纠正 只能检查单次的错误&#xff0c;不能完全抗干扰 可以按照上面的方法来循环构造 移存码可以通过前推后推来实现

pycharm配置python3.8版本专门用于undecteded_chromedriver测试

pycharm配置python3.8版本专门用于undecteded_chromedriver测试 作者&#xff1a;虚坏叔叔 博客&#xff1a;https://pay.xuhss.com 早餐店不会开到晚上&#xff0c;想吃的人早就来了&#xff01;&#x1f604; 一、Pycharm及python环境的配置 1.安装python-3.8.7rc1-amd64.e…