当前位置: 首页 > wzjs >正文

优化型网站建设的基本要求wordpress 防源码抓取

优化型网站建设的基本要求,wordpress 防源码抓取,厦门建行网站,专业的网站建设官网文章目录 声明配置yum源安装docker安装 kubeadm,kubelet 和 kubectl部署主节点其他节点加入集群安装网络插件 声明 由于看了几个k8s的教程,都存在各种问题,自己搭建的时候,踩了不少坑,最后还是靠百度csdnchatGPT才搭建…

文章目录

    • 声明
    • 配置yum源
    • 安装docker
    • 安装 kubeadm,kubelet 和 kubectl
    • 部署主节点
    • 其他节点加入集群
    • 安装网络插件

声明

由于看了几个k8s的教程,都存在各种问题,自己搭建的时候,踩了不少坑,最后还是靠百度+csdn+chatGPT才搭建了起来,所以决定单独起个帖子,结合这几个教程,出一版搭建参考。
本次示范使用三台虚拟机,分别是119,120和121,仅供学习参考,另外建议每做一个步骤,就对虚拟机或者服务器生成一次备份,避免哪一步操作出错。

配置yum源

如果用的是centos7的话,yum安装一些东西的时候会报Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64,可参考下面解决方案:

cd /etc/yum.repos.d/
mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.bak
# 如果无法wget可以直接浏览器下载下来后放进去 
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  #之后执行
yum clean all
yum update
yum makecache#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld#关闭 selinux
selinux:linux 的安全系统
sed -i 's/enforcing/disabled/' /etc/selinux/config#关闭 swap
sed -ri 's/.*swap.*/#&/' /etc/fstab#设置网桥参数
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF#时间同步(非常重要)
yum install ntpdate -y
ntpdate time.windows.com备注:如果 yum 下载过程中断开,造成 yum 程序锁定,可运行以下命令关闭 yum 程序
rm -f /var/run/yum.pid#在 master 节点为各主机的 IP 命名cat >> /etc/hosts << EOF
192.168.10.119 master
192.168.10.120 node1
192.168.10.121 node2
EOF

配置完重启虚拟机或者服务器。

安装docker

# yum install -y docker-ce 没有可用的软件包的解决方案
yum -y install yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#如果 yum 下载过程中断开,造成 yum 程序锁定,可运行以下命令关闭 yum 程序
rm -f /var/run/yum.pid
# 安装docker-ce
yum -y install docker-ce

接下来访问这个网址:阿里云镜像加速器,跟着页面指引配置镜像加速器
在这里插入图片描述

sudo systemctl daemon-reload
sudo systemctl restart docker
# 配置开机自启动systemctl enable docker

安装 kubeadm,kubelet 和 kubectl

#配置 yum 源镜像
cat <<EOF > /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
EOF#执行以下指令,设置各种密匙
curl -fsSL https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg | sudo gpg --importcurl -fsSL https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg | sudo gpg --importsudo rpm --import https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgsudo yum clean all
sudo yum makecache

执行yum makecache的时候,会有以下提示,输入y,回车:
在这里插入图片描述

#安装软件
yum install kubelet-1.19.4 kubeadm-1.19.4 kubectl-1.19.4 -y
#自动运行软件
systemctl enable kubelet.service
#查看是否安装成功
yum list installed | grep kubelet
yum list installed | grep kubeadm
yum list installed | grep kubectl

在这里插入图片描述

部署主节点

在master节点执行:

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

其中192.168.10.119为主节点的ip地址,用ifconfig查看即可。

执行后如下图所示:
在这里插入图片描述
把里面的指令复制出来执行,主要是这三个:

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

之后执行一下:

kubectl get nodes

如下图所示为正常:
在这里插入图片描述

其他节点加入集群

将之前master节点看到的这段复制过来,贴到其他节点上执行

在这里插入图片描述
在这里插入图片描述

执行成功后,在主节点执行以下指令确认:

kubectl get nodes

在这里插入图片描述

安装网络插件

上传kube-flannel.yml到主节点,执行kubectl apply -f kube-flannel.yml,以下是文件内容:

apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:name: psp.flannel.unprivilegedannotations:seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/defaultseccomp.security.alpha.kubernetes.io/defaultProfileName: docker/defaultapparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/defaultapparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
spec:privileged: falsevolumes:- configMap- secret- emptyDir- hostPathallowedHostPaths:- pathPrefix: "/etc/cni/net.d"- pathPrefix: "/etc/kube-flannel"- pathPrefix: "/run/flannel"readOnlyRootFilesystem: false# Users and groupsrunAsUser:rule: RunAsAnysupplementalGroups:rule: RunAsAnyfsGroup:rule: RunAsAny# Privilege EscalationallowPrivilegeEscalation: falsedefaultAllowPrivilegeEscalation: false# CapabilitiesallowedCapabilities: ['NET_ADMIN']defaultAddCapabilities: []requiredDropCapabilities: []# Host namespaceshostPID: falsehostIPC: falsehostNetwork: truehostPorts:- min: 0max: 65535# SELinuxseLinux:# SELinux is unused in CaaSPrule: 'RunAsAny'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:name: flannel
rules:- apiGroups: ['extensions']resources: ['podsecuritypolicies']verbs: ['use']resourceNames: ['psp.flannel.unprivileged']- apiGroups:- ""resources:- podsverbs:- get- apiGroups:- ""resources:- nodesverbs:- list- watch- apiGroups:- ""resources:- nodes/statusverbs:- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:name: flannel
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: flannel
subjects:
- kind: ServiceAccountname: flannelnamespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:name: flannelnamespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:name: kube-flannel-cfgnamespace: kube-systemlabels:tier: nodeapp: flannel
data:cni-conf.json: |{"name": "cbr0","cniVersion": "0.3.1","plugins": [{"type": "flannel","delegate": {"hairpinMode": true,"isDefaultGateway": true}},{"type": "portmap","capabilities": {"portMappings": true}}]}net-conf.json: |{"Network": "10.244.0.0/16","Backend": {"Type": "vxlan"}}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-ds-amd64namespace: kube-systemlabels:tier: nodeapp: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linux- key: kubernetes.io/archoperator: Invalues:- amd64hostNetwork: truetolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cniimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:amd64command:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:amd64command:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"limits:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespacevolumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/volumes:- name: runhostPath:path: /run/flannel- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-ds-arm64namespace: kube-systemlabels:tier: nodeapp: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linux- key: kubernetes.io/archoperator: Invalues:- arm64hostNetwork: truetolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cniimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:arm64command:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:arm64command:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"limits:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespacevolumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/volumes:- name: runhostPath:path: /run/flannel- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-ds-armnamespace: kube-systemlabels:tier: nodeapp: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linux- key: kubernetes.io/archoperator: Invalues:- armhostNetwork: truetolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cniimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:armcommand:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:armcommand:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"limits:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespacevolumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/volumes:- name: runhostPath:path: /run/flannel- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-ds-ppc64lenamespace: kube-systemlabels:tier: nodeapp: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linux- key: kubernetes.io/archoperator: Invalues:- ppc64lehostNetwork: truetolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cniimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:ppc64lecommand:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:ppc64lecommand:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"limits:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespacevolumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/volumes:- name: runhostPath:path: /run/flannel- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-ds-s390xnamespace: kube-systemlabels:tier: nodeapp: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linux- key: kubernetes.io/archoperator: Invalues:- s390xhostNetwork: truetolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cniimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:s390xcommand:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: registry.cn-zhangjiakou.aliyuncs.com/test-lab/coreos-flannel:s390xcommand:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"limits:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespacevolumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/volumes:- name: runhostPath:path: /run/flannel- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg

执行一下指令:

kubectl apply -f kube-flannel.yml
# 如果自己发现这个文件有问题,想替换的话,可以删掉
# kubectl delete -f kube-flannel.yml

在这里插入图片描述

执行后先执行这个指令:

 kubectl get pods -n kube-system

在这里插入图片描述
基本可以看到这两个为0,其他为1,为什么呢?

执行kubectl get nodes,节点也是noready的状态:
在这里插入图片描述

执行以下指令去查看其中一个节点:

# nodename换成你要查的,在主节点上执行,例如这里我查的是node1
kubectl describe node <node-name>

这里的信息也提示网络组件其实还没准备好:
在这里插入图片描述

在主节点输入以下指令查看一下日志:

journalctl -u kubelet -xe

在这里插入图片描述

把这两个关键信息到网上查,才知道 /etc/cni/net.d是跟我们安装的网络flannel有关的,这说明了虽然flannel安装了,但是仍然存在问题。

Flannel 会自动安装 CNI 插件到 /opt/cni/bin,于是我去看了下这个地方:

ls /opt/cni/bin

在这里插入图片描述

根据查看的结果,我发现里面少了好几个文件夹,包括flannel,这就说明其实CNI插件没有安装成功。

在这里插入图片描述

知道问题了,就很好解决了,接下来就是在每个节点上都安装CNI插件:

wget https://github.com/flannel-io/cni-plugin/releases/download/v1.1.0/flannel-amd64 -O /opt/cni/bin/flannel
chmod +x /opt/cni/bin/flannel

安装后重新执行ls /opt/cni/bin 检查了一下,发现终于完整了:

在这里插入图片描述

ls /etc/cni/net.d/ 检查了一下,也有相关配置文件:

在这里插入图片描述
在这里插入图片描述

{"name": "cbr0","cniVersion": "0.3.1","plugins": [{"type": "flannel","delegate": {"hairpinMode": true,"isDefaultGateway": true}},{"type": "portmap","capabilities": {"portMappings": true}}]
}

然后执行以下指令,方便重新生成CNI相关配置到k8s里:

# 主节点执行
kubectl delete pod -n kube-system -l app=flannel
# 主从节点都要执行
sudo systemctl restart kubelet# 主节点执行
[root@master ~]# kubectl get pods -n kube-system -l app=flannel
NAME                          READY   STATUS    RESTARTS   AGE
kube-flannel-ds-amd64-4dk66   1/1     Running   0          33s
kube-flannel-ds-amd64-g76mr   1/1     Running   0          23s
kube-flannel-ds-amd64-zdklx   1/1     Running   0          34s[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    master   62m   v1.19.4
node1    Ready    <none>   59m   v1.19.4
node2    Ready    <none>   59m   v1.19.4

之后执行:

 kubectl get pods -n kube-system

如果还有这种
在这里插入图片描述

可以先删掉对应的pod,k8s会自动恢复的,例如上面的三个异常pod:

kubectl delete pod -n kube-system etcd-master
kubectl delete pod -n kube-system kube-controller-manager-master
kubectl delete pod -n kube-system kube-scheduler-master
kubectl get pods -n kube-system

在这里插入图片描述

如果还是不行,就用这个指令去查看对应的pod的日志,然后根据日志报错,上网搜搜看怎么解决:

#把name换成你要查的pod,pod是用kubectl get pods -n kube-system来查的
# 例如下图的etcd-master,可以用指令kubectl logs -n kube-system etcd-master
kubectl logs -n kube-system name

在这里插入图片描述

在这里插入图片描述

http://www.dtcms.com/wzjs/552635.html

相关文章:

  • 网站服务器建设上海网络推广公司网站
  • 做图表的网站模板网站会影响网站优化吗
  • 建设网站用哪个主机好如何在网站上推广自己的链接
  • 批量网站建设开元酒店集团品牌建设
  • 兴国县城乡规划建设局网站就业网站建设方案
  • 融水苗族自治县网站建设公司娄底360seo优化公司
  • 网站设计中级南昌那个公司做网站好
  • 国外做做网站wordpress默认缩略图
  • 网站程序购买微信公众号要钱吗
  • 电商网站用php做的吗骏域网站建设专家电脑版
  • 网站对公司有什么好处南海网站建设多少钱
  • 北京高端网站建设费用做标准件生意上什么网站
  • php做的静态网站怎么加密网站搭建报价单
  • 国外虚拟物品交易网站办公室装修设计app
  • 供电公司网站建设内容宁波专门做网站
  • 嘉兴网站建设一薇做企业服务这个行业怎么样
  • 怎样将整个网站公司网站建设深圳
  • 怎么做本地网站tcga做多因素分析的网站
  • 重庆网站建设近重庆零臻科技网站域名实名证明
  • 网站世界排名怎么做wordpress怎么连接主机
  • 公司网站策划宣传生成二维码的网站
  • 学做网站需要学什么网页制作作品免费下载
  • 网站程序代码优化社交app系统开发
  • 做视频网站的备案要求男生和女生做污的事情免费网站
  • 建筑工程公司网站模板下载福州百诚互联
  • 做网站的的价位苏州市吴中区建设局网站
  • 网站开发与网站设计区别企业免费网站制作
  • wordpress网站开发代码移动网站建设自助建站
  • 上海住房与建设部网站百度抓取网站登录
  • 酒店网站建设的构思做网站编程在程序