K3S部署

2024-06-15 08:20
文章标签 部署 k3s

本文主要是介绍K3S部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

k3s官网

一个server端、一个Agent端,
Kubernetes control plane 组件的操作都封装在单个二进制文件和进程中

requirements

  • 最低1U 512MB K3s 的性能取决于数据库的性能。
  • 为确保最佳速度,我们建议尽可能使用 SSD K3s 服务器
  • 需要端口 6443 才能被所有节点访问2379,2380。

脚本方式安装

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
  • kubeconfig 文件位于/etc/rancher/k3s/k3s.yaml

加载镜像(所有节点都需要操作)

github上找到对应release下载

mkdir -p /var/lib/rancher/k3s/agent/images/
wget https://github.com/k3s-io/k3s/releases/download/v1.30.0%2Bk3s1/k3s-airgap-images-amd64.tar.gz
ctr i import  k3s-airgap-images-amd64.tar

加入节点(如果你想-可选)

K3S_URL 参数会导致安装程序将 K3s 配置为 Agent 而不是 Server。K3s Agent 将注册到在 URL 上监听的 K3s Server。myserver写server IP地址
K3S_TOKEN 使用的值存储在 Server 节点上的 /var/lib/rancher/k3s/server/node-token 中

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

=========================================

卸载server(在server上执行)

分别会在各个节点上有相应的卸载脚本

/usr/local/bin/k3s-uninstall.sh

卸载agent(在agent上执行)

/usr/local/bin/k3s-agent-uninstall.sh
#/usr/local/bin/k3s-killall.sh	停止
#systemctl start k3s-agent 启动

=========================================

创建镜像仓库

创建镜像仓库日后在写

没用的东西不看

k3s Installation
Introduction
In this lab we will be installing k3s.Prerequisite
All of our labs are built upon one another. Please make sure all previous labs are completed before starting this lab.Workflow
Hardware
For this lab we are going to need at least two virtual machine or a physical machine to install k3s on. The machines need to be of a particular architecture outlined here:x86_64
armhf
arm64/aarch64
s390x
Each of these machines need the minimum requirements:CPU: 1 core
Ram: 512 MB
Recommended:CPU: 2 cores
RAM: 1 GB
Operating System
K3s will work on most modern Linux system. Note there are differences for CentOS/Red Hat and Raspberry Pi OS.For these labs we will be using openSUSE Leap.k3s Version
In this course we are going to do an upgrade to a newer version of k3s. To do this we are going to need to find the latest version of k3s and take the stable release one minor version back.For example if the latest release of the latest version of k3s is v1.27.4+k3s1 we are going to want to use the v1.26.7+k3s1 of k3s.You can find the latest versions of k3s here.NOTE: don't try this lab with any marked as Pre-release.Server Script Install
One of the easiest ways to install k3s is by the installation script.You will need to ssh in to the server node.The install script lives here https://get.k3s.io/. To run this we are going to use a few flags:curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.26.7+k3s1 INSTALL_K3S_EXEC="server --cluster-init --node-ip 192.168.3.2 --node-external-ip 192.168.3.2" sh -s -
NOTE: the k3s version might not be the one prior to the latest! Check here for the correct version.This setups up the server installation on our server VM.To test to see if everything is running k3s comes with kubectl so while still logged in to our server instance we can do a quick check to make sure all is running:k3s kubectl get pods -A
And you should see the following output:NAMESPACE     NAME                                     READY   STATUS      RESTARTS   AGE
kube-system   local-path-provisioner-957fdf8bc-sd297   1/1     Running     0          107s
kube-system   coredns-77ccd57875-sbrsl                 1/1     Running     0          107s
kube-system   helm-install-traefik-crd-7926x           0/1     Completed   0          107s
kube-system   helm-install-traefik-rswvl               0/1     Completed   1          107s
kube-system   metrics-server-648b5df564-5xbcw          1/1     Running     0          107s
kube-system   svclb-traefik-ea396d7d-4h9f6             2/2     Running     0          53s
kube-system   traefik-64f55bb67d-5cqxm                 1/1     Running     0          53s
Once you see that the system pods are either Running or Completed we need to get the token from the server to do so run the following command:sudo cat /var/lib/rancher/k3s/server/node-token
You will get the token needed for adding the agent (Note: it will not be this exact key):K105b9c68df80752c8f9d498097b764a35f9ba2c0220b2ea8951cef3aca111d9f33::server:2855bde078f38f3964f3f36e6e37dfbb
To logout of the server vm.Agent Script Install
Now we need to install k3s on the agent vm.First let's remote in to our agent vm.Again the install script lives here https://get.k3s.io/. To run this we are going to use a few flags (Note: this will take a few moments.):curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.26.7+k3s1 INSTALL_K3S_EXEC="agent --server https://192.168.3.2:6443 --node-ip 192.168.3.3 --node-external-ip 192.168.3.3" K3S_TOKEN=K105b9c68df80752c8f9d498097b764a35f9ba2c0220b2ea8951cef3aca111d9f33::server:2855bde078f38f3964f3f36e6e37dfbb K3S_NODE_NAME=agent sh -
NOTE: the k3s version might not be the one prior to the latest! Check here for the correct version.NOTE: The K3S_TOKEN is the token we pulled from the server earlier.kubectl Remotely
Just so we don't have to remain logged into the server VM let's copy down the config:ssh server -c "sudo cat /etc/rancher/k3s/k3s.yaml" > k3s.yaml
This will copy down the KUBECONFIG file down from the server.We are going to need to modify the k3s.yaml file:apiVersion: v1
clusters:
- cluster:certificate-authority-data: LS0tLS1CRUserver: https://127.0.0.1:6443name: default
contexts:
- context:cluster: defaultuser: defaultname: default
current-context: default
kind: Config
preferences: {}
users:
- name: defaultuser:client-certificate-data: LS0tLS1CRUclient-key-data: LS0tLS1CRU(Note: the certificate data has been cut down.)We are going to need to change the variable of the server from:server: https://127.0.0.1:6443
To the following:server: https://192.168.3.2:6443
Now we are going to copy this k3s.yaml file to our .kube directory:cp k3s.yaml $HOME/.kube
From there we are going to set the KUBECONFIG variable to the location of the k3s.yaml file:export KUBECONFIG=$HOME/.kube/k3s.yaml
To test to see if this works we can run the following this command:kubectl get nodes
And you should see something like this:NAME     STATUS   ROLES                       AGE    VERSION
agent    Ready    <none>                      21s    v1.26.7+k3s1
server   Ready    control-plane,etcd,master   3m9s   v1.26.7+k3s1

这篇关于K3S部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1062920

相关文章

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

Linux流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

nginx部署https网站的实现步骤(亲测)

《nginx部署https网站的实现步骤(亲测)》本文详细介绍了使用Nginx在保持与http服务兼容的情况下部署HTTPS,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录步骤 1:安装 Nginx步骤 2:获取 SSL 证书步骤 3:手动配置 Nginx步骤 4:测

Tomcat高效部署与性能优化方式

《Tomcat高效部署与性能优化方式》本文介绍了如何高效部署Tomcat并进行性能优化,以确保Web应用的稳定运行和高效响应,高效部署包括环境准备、安装Tomcat、配置Tomcat、部署应用和启动T... 目录Tomcat高效部署与性能优化一、引言二、Tomcat高效部署三、Tomcat性能优化总结Tom

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

本地私有化部署DeepSeek模型的详细教程

《本地私有化部署DeepSeek模型的详细教程》DeepSeek模型是一种强大的语言模型,本地私有化部署可以让用户在自己的环境中安全、高效地使用该模型,避免数据传输到外部带来的安全风险,同时也能根据自... 目录一、引言二、环境准备(一)硬件要求(二)软件要求(三)创建虚拟环境三、安装依赖库四、获取 Dee