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

相关文章

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

SpringBoot配置Ollama实现本地部署DeepSeek

《SpringBoot配置Ollama实现本地部署DeepSeek》本文主要介绍了在本地环境中使用Ollama配置DeepSeek模型,并在IntelliJIDEA中创建一个Sprin... 目录前言详细步骤一、本地配置DeepSeek二、SpringBoot项目调用本地DeepSeek前言随着人工智能技

通过Docker Compose部署MySQL的详细教程

《通过DockerCompose部署MySQL的详细教程》DockerCompose作为Docker官方的容器编排工具,为MySQL数据库部署带来了显著优势,下面小编就来为大家详细介绍一... 目录一、docker Compose 部署 mysql 的优势二、环境准备与基础配置2.1 项目目录结构2.2 基

CentOS 7部署主域名服务器 DNS的方法

《CentOS7部署主域名服务器DNS的方法》文章详细介绍了在CentOS7上部署主域名服务器DNS的步骤,包括安装BIND服务、配置DNS服务、添加域名区域、创建区域文件、配置反向解析、检查配置... 目录1. 安装 BIND 服务和工具2.  配置 BIND 服务3 . 添加你的域名区域配置4.创建区域

OpenManus本地部署实战亲测有效完全免费(最新推荐)

《OpenManus本地部署实战亲测有效完全免费(最新推荐)》文章介绍了如何在本地部署OpenManus大语言模型,包括环境搭建、LLM编程接口配置和测试步骤,本文给大家讲解的非常详细,感兴趣的朋友一... 目录1.概况2.环境搭建2.1安装miniconda或者anaconda2.2 LLM编程接口配置2

大数据spark3.5安装部署之local模式详解

《大数据spark3.5安装部署之local模式详解》本文介绍了如何在本地模式下安装和配置Spark,并展示了如何使用SparkShell进行基本的数据处理操作,同时,还介绍了如何通过Spark-su... 目录下载上传解压配置jdk解压配置环境变量启动查看交互操作命令行提交应用spark,一个数据处理框架

如何使用Docker部署FTP和Nginx并通过HTTP访问FTP里的文件

《如何使用Docker部署FTP和Nginx并通过HTTP访问FTP里的文件》本文介绍了如何使用Docker部署FTP服务器和Nginx,并通过HTTP访问FTP中的文件,通过将FTP数据目录挂载到N... 目录docker部署FTP和Nginx并通过HTTP访问FTP里的文件1. 部署 FTP 服务器 (

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

Ubuntu 22.04 服务器安装部署(nginx+postgresql)

《Ubuntu22.04服务器安装部署(nginx+postgresql)》Ubuntu22.04LTS是迄今为止最好的Ubuntu版本之一,很多linux的应用服务器都是选择的这个版本... 目录是什么让 Ubuntu 22.04 LTS 变得安全?更新了安全包linux 内核改进一、部署环境二、安装系统

JAVA集成本地部署的DeepSeek的图文教程

《JAVA集成本地部署的DeepSeek的图文教程》本文主要介绍了JAVA集成本地部署的DeepSeek的图文教程,包含配置环境变量及下载DeepSeek-R1模型并启动,具有一定的参考价值,感兴趣的... 目录一、下载部署DeepSeek1.下载ollama2.下载DeepSeek-R1模型并启动 二、J