k8s安装部署

news2025/1/11 7:04:42

1、基础环境

所有机器执行以下操作

hostname        ip
k8s-master192.168.0.121
k8s-node1192.168.0.102
k8s-node2192.168.0.160

docker version:20.10.7

k8s相关插件version:1.20.9

#各个机器设置自己的域名
hostnamectl set-hostname xxxx


# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

#关闭swap
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

2、安装kubelet、kubeadm、kubectl

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
   http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF


sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes

sudo systemctl enable --now kubelet

3、使用kubeadm引导集群

3.1、下载各个节点需要的镜像

sudo tee ./images.sh <<-'EOF'
#!/bin/bash
images=(
kube-apiserver:v1.20.9
kube-proxy:v1.20.9
kube-controller-manager:v1.20.9
kube-scheduler:v1.20.9
coredns:1.7.0
etcd:3.4.13-0
pause:3.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName
done
EOF
   
chmod +x ./images.sh && ./images.sh

3.2、初始化主节点master

#所有机器添加master域名映射,以下需要修改为自己的
echo "192.168.0.121  cluster-endpoint" >> /etc/hosts



#主节点初始化
kubeadm init \
--apiserver-advertise-address=192.168.0.121 \
--control-plane-endpoint=cluster-endpoint \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16



初始化成功后,将这块复制出来,为后面添加工作节点用

3.3、执行kubectl命令时,报8080 refused

#在master节点上执行

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
 

#复制admin.conf到各个工作节点,在master节点上执行此命令,ip为node节点ip
scp /etc/kubernetes/admin.conf 192.168.0.102:/etc/kubernetes/admin.conf
scp /etc/kubernetes/admin.conf 192.168.0.160:/etc/kubernetes/admin.conf

#在node节点上执行,设置kubeconfig文件
export KUBECONFIG=/etc/kubernetes/admin.conf
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

 source ~/.bash_profile

3.4、网络插件

curl https://docs.projectcalico.org/v3.8/manifests/calico.yaml -O

kubectl apply -f calico.yaml

# 添加node节点到master里

#需要先把master节点的6443端口开放

firewall-cmd --zone=public --add-port=6443/tcp --permanent

systemctl restart firewalld.service

firewall-cmd --reload


firewall-cmd --list-ports

分别在node节点上执行

kubeadm join cluster-endpoint:6443 --token x5g4uy.wpjjdbgra92s25pp \
	--discovery-token-ca-cert-hash sha256:6255797916eaee52bf9dda9429db616fcd828436708345a308f4b917d3457a22

执行完后,在master节点上执行 ,验证集群节点状态

kubectl get nodes

 如果上面token失效,下面命令可生产新的token

#新令牌
kubeadm token create --print-join-command

4、部署dashboard可视化界面

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml

下载不下来,用下面的,先创建个dashboard.yaml文件

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: Namespace
metadata:
  name: kubernetes-dashboard

---

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard

---

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard

---

apiVersion: v1
kind: Secret
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-certs
  namespace: kubernetes-dashboard
type: Opaque

---

apiVersion: v1
kind: Secret
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-csrf
  namespace: kubernetes-dashboard
type: Opaque
data:
  csrf: ""

---

apiVersion: v1
kind: Secret
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-key-holder
  namespace: kubernetes-dashboard
type: Opaque

---

kind: ConfigMap
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-settings
  namespace: kubernetes-dashboard

---

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
rules:
  # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
  - apiGroups: [""]
    resources: ["secrets"]
    resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
    verbs: ["get", "update", "delete"]
    # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["kubernetes-dashboard-settings"]
    verbs: ["get", "update"]
    # Allow Dashboard to get metrics.
  - apiGroups: [""]
    resources: ["services"]
    resourceNames: ["heapster", "dashboard-metrics-scraper"]
    verbs: ["proxy"]
  - apiGroups: [""]
    resources: ["services/proxy"]
    resourceNames: ["heapster", "http:heapster:", "https:heapster:", "dashboard-metrics-scraper", "http:dashboard-metrics-scraper"]
    verbs: ["get"]

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
rules:
  # Allow Metrics Scraper to get metrics from the Metrics server
  - apiGroups: ["metrics.k8s.io"]
    resources: ["pods", "nodes"]
    verbs: ["get", "list", "watch"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: kubernetes-dashboard
subjects:
  - kind: ServiceAccount
    name: kubernetes-dashboard
    namespace: kubernetes-dashboard

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kubernetes-dashboard
subjects:
  - kind: ServiceAccount
    name: kubernetes-dashboard
    namespace: kubernetes-dashboard

---

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
        - name: kubernetes-dashboard
          image: kubernetesui/dashboard:v2.3.1
          imagePullPolicy: Always
          ports:
            - containerPort: 8443
              protocol: TCP
          args:
            - --auto-generate-certificates
            - --namespace=kubernetes-dashboard
            # Uncomment the following line to manually specify Kubernetes API server Host
            # If not specified, Dashboard will attempt to auto discover the API server and connect
            # to it. Uncomment only if the default does not work.
            # - --apiserver-host=http://my-address:port
          volumeMounts:
            - name: kubernetes-dashboard-certs
              mountPath: /certs
              # Create on-disk volume to store exec logs
            - mountPath: /tmp
              name: tmp-volume
          livenessProbe:
            httpGet:
              scheme: HTTPS
              path: /
              port: 8443
            initialDelaySeconds: 30
            timeoutSeconds: 30
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            runAsUser: 1001
            runAsGroup: 2001
      volumes:
        - name: kubernetes-dashboard-certs
          secret:
            secretName: kubernetes-dashboard-certs
        - name: tmp-volume
          emptyDir: {}
      serviceAccountName: kubernetes-dashboard
      nodeSelector:
        "kubernetes.io/os": linux
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
        - key: node-role.kubernetes.io/master
          effect: NoSchedule

---

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: dashboard-metrics-scraper
  name: dashboard-metrics-scraper
  namespace: kubernetes-dashboard
spec:
  ports:
    - port: 8000
      targetPort: 8000
  selector:
    k8s-app: dashboard-metrics-scraper

---

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: dashboard-metrics-scraper
  name: dashboard-metrics-scraper
  namespace: kubernetes-dashboard
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: dashboard-metrics-scraper
  template:
    metadata:
      labels:
        k8s-app: dashboard-metrics-scraper
      annotations:
        seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'
    spec:
      containers:
        - name: dashboard-metrics-scraper
          image: kubernetesui/metrics-scraper:v1.0.6
          ports:
            - containerPort: 8000
              protocol: TCP
          livenessProbe:
            httpGet:
              scheme: HTTP
              path: /
              port: 8000
            initialDelaySeconds: 30
            timeoutSeconds: 30
          volumeMounts:
          - mountPath: /tmp
            name: tmp-volume
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            runAsUser: 1001
            runAsGroup: 2001
      serviceAccountName: kubernetes-dashboard
      nodeSelector:
        "kubernetes.io/os": linux
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
        - key: node-role.kubernetes.io/master
          effect: NoSchedule
      volumes:
        - name: tmp-volume
          emptyDir: {}
#执行命令
kubectl apply -f dashboard.yaml

 4.1、设置访问端口

# 执行命令,type: ClusterIP 改为 type: NodePort

kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard

4.2、开放dashboard端口

kubectl get svc -A |grep kubernetes-dashboard
## 找到端口,在安全组放行,开放30956端口

 

 

设置完后,访问dashboard界面,https://任意节点ip:30956/

https://191.168.0.160:30956/

 

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

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

相关文章

Java中令人惊艳的五大算法,你知道多少?

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

Golang - 选项模式 vs 构建器模式

在使用Golang创建复杂对象时&#xff0c;常用的两种模式是选项模式&#xff08;Options pattern&#xff09;和构建器模式&#xff08;Builder pattern&#xff09;。这两种模式各有优缺点&#xff0c;选择适合项目需求的模式取决于具体情况。 问题 假设我们想创建一个具有许…

【HTTP 协议】掌握 Web 的核心技术

哈喽&#xff0c;大家好~我是你们的老朋友&#xff1a;保护小周ღ 谈起 HTTP 协议&#xff08;超文本传输协议&#xff09;&#xff0c;不知道大家第一次是从什么地方了解到这个协议的呢&#xff1f;在真实的网络环境中网络协议的种类非常多&#xff0c;其中有一些耳熟能详的…

GBASE南大通用5月份公司动态一览

产品动态 5月初&#xff0c;GBASE南大通用两款新产品&#xff1a;GBase 8c V5.0和GBase 8s V8.8.5于鲲鹏开发者大会主论坛商业发行版联合发布仪式上正式发布。新版本与上一版本功能特性保持兼容&#xff0c;并在算子能力、用户级别审计、兼容性等方面全面增强&#xff0c;支持一…

最新版本 Stable Diffusion 开源 AI 绘画工具之微调模型篇

✨ 目录 &#x1f388; 模型种类&#x1f388; 变分自动编码器 / VAE&#x1f388; 美学梯度 / Aesthetic Gradients&#x1f388; 大型语言模型的低阶自适应 / LoRA&#x1f388; 超网络模型 / Hypernetwork&#x1f388; 微调模型 / LyCORIS &#x1f388; 模型种类 当你打开…

jacoco检测功能或自动化测试覆盖率

参考文档&#xff1a;http://t.csdn.cn/QqCSh http://t.csdn.cn/HonVL 目录 下载jacoco 启动jacocoagent监控被测项目 执行手工测试 生成exec文件 生成report报告 jacoco代码覆盖率报告分析 下载jacoco http://t.csdn.cn/HonVL 我下载的最新的 jacoco-0.8.10.zip 下…

虚拟化技术 — Cgroups 与 Namespaces 支撑实现的操作系统虚拟化

目录 文章目录 目录操作系统虚拟化&#xff08;容器技术&#xff09;的发展历程ChrootCgroupsCgroup SubsystemsCgroup FilesystemCgroup HierarchyCgroups 的操作规则Cgroups 的代码实现 NamespacesUTS namespacePID namespaceIPC namespaceMount namespaceNetwork namespaceU…

mysql order by 索引问题综合分析

一&#xff0c;文章1 Mysql-索引失效 order by优化_orderby索引失效_zyk1.的博客-CSDN博客 总结&#xff1a; 0&#xff0c;索引 与 查询条件 与 排序字段关系&#xff0c;Using filesort出现场景 1.联合索引&#xff0c;最左匹配原则&#xff0c;不仅查询条件需要遵循&…

vivado FIFO的Standard 和 FWFT模式

vivado FIFO的Standard 和 FWFT模式 Standard 模式读操作 对于标准 FIFO 读取操作&#xff0c;在断言读有效后&#xff0c;如果 FIFO 非空&#xff0c;存储在FIFO中的下一个数据被驱动到输出总线&#xff08;dout&#xff09;上和VALID标志有效。 下图显示标准模式下的读数据…

ChatGPT介绍与使用场景

ChatGPT是OpenAI开发的一款基于GPT-3和GPT-4的人工智能聊天机器人。“GPT"代表的是"Generative Pre-trained Transformer”&#xff0c;这是一种深度学习技术&#xff0c;使用人工神经网络来生成类似人类的文本。 ChatGPT能够处理各种对话任务&#xff0c;包括回答问…

教您如何快速自助搭建一个元宇宙场景

【导语】 在数字化时代&#xff0c;营销方式正经历着巨大的变革。而在这场变革的浪潮中&#xff0c;元宇宙编辑器凭借其独特的元宇宙展厅解决方案&#xff0c;为企业和个人提供了快速、简便的自助搭建元宇宙场景的机会。 今天&#xff0c;让我们一起走进元宇宙编辑器的世界&…

如何将Windows 7系统镜像部署到不同的硬件计算机?

案例&#xff1a;将Windows 7系统镜像恢复到另一台电脑 “我有一台运行 Windows 7 的电脑&#xff0c;我已经创建了一个系统镜像并希望将其加载到另一台电脑上。但是&#xff0c;当我运行恢复控制台时&#xff0c;我不断收到错误消息。这让我想知道是否可以创建 Windows 7 系…

前端面试技巧?第一手面试真题!

面试有哪些套路和技巧&#xff1f; 第一次去面试&#xff0c;该注意什么&#xff1f; 怎么说话能打动面试官&#xff0c;成功入职&#xff1f; 当你褪去青涩&#xff0c;将头发梳成大人模样走向面试之路时&#xff0c;你们的搜索记录和行为早已暴露了自己内心状态&#xff1a…

数据结构和算法的基本概念

数据结构概念 1.数据&#xff1a;所有能输入计算机且能被计算机处理的符号总称 2.数据元素&#xff1a;是数据的基本单位&#xff0c;表示数据集合中的一个个体。 3 .数据项&#xff1a;数据元素中有独立含义的最小单位。 数据结构&#xff1a;相互之间存在一定关系的数据元素的…

Layui时间选择设置只能选择整点半点,并隐藏秒钟部分

文章目录 1.整点半点选择2.隐藏秒选择部分3.默认值处理3.1 操作done函数3.2 操作ready函数 1.整点半点选择 处理思路&#xff1a;通过循环将使用不到的时间点去除掉&#xff0c;关键代码位于ready函数 //选择起止时间 layui.laydate.render({elem: .laydate-times,type: &quo…

第五章 Electron|Node 使用cheerio 爬虫

一、cheerio是什么可以做什么 &#x1f447; &#x1f447; &#x1f447; Cheerio是一个快速、灵活且精益的jQuery核心实现&#xff0c;用于在Node.js环境中解析HTML文档。它可以帮助您在服务器端轻松地从HTML文档中提取数据&#xff0c;比如从网页中提取文章标题、内容、图片…

【JVM】.class文件如何在JVM中运行的?

一、先认识JVM的组成 java虚拟机整体包括&#xff1a;类加载系统、运行时数据区、执行引擎、垃圾回收器。 &#xff08;1&#xff09;方法区&#xff1a;线程共享&#xff0c;存储Class信息、常量、静态变量等等&#xff1b; jdk1.6~1.7时称为永久代&#xff0c;存储常量、Cla…

js常见面试题整理

1&#xff1a;JavaScript 有哪些数据类型 答&#xff1a; JavaScript 的数据类型分为原始类型和对象类型。 原始类型有 7 种&#xff0c;分别是&#xff1a; BooleanNumberBigIntStringNullUndefinedSymbol 对象类型&#xff08;也称引用类型&#xff09;是一个泛称&#x…

vue3 中使用indexDb

1.indexDb.js const indexDB window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB; class IndexDBCache {// 构造函数constructor() {this._db null; //数据库this._transaction null; //事务this._request null;this._dbName "loginInfoDb"; …

API ‘variantOutput.getPackageLibrary()‘已过时的解决方法

一个发布到maven central的android库项目&#xff0c;为了方便管理&#xff0c;在build.gradle文件中加入了打包处理的一段脚本&#xff1a; //生成aarlibraryVariants.all { variant ->def name "library-${versionMajor}.${versionMinor}.${versionPatch}.aar"…