Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the rapid deployment and use of K3s

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "what is the rapid deployment and use of K3s". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the rapid deployment and use of K3s" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.

1. Install k3s1.1 automatic installation

Master node installation

Or, install it directly, as follows:

Curl-sfL https://get.k3s.io | sh-

Install.sh for downloading K3s provides tools to install to systemd or openrc, and K3s will be installed to serve the system.

The configuration file kubeconfig is written to / etc/rancher/k3s/k3s.yaml and the service will start automatically. The installation script also installs K3s and other tools, such as kubectl, crictl, k3s-killall.sh, and k3s-uninstall.sh, and can run the following command to get the node status:

Sudo kubectl get nodes

K3S_TOKEN is created on the master server / var/lib/rancher/k3s/server/node-token.

The ⚠️ has been deployed, but the service is not available. As follows:

My test environment is Ubuntu 19.10.Take a try with raspbian next time.

Ubuntu@ubuntu:~$ sudo kubectl cluster-infoTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.The connection to the server 127.0.0.1 was refused-did you specify the right host or port?

Work node installation

If you install K3s on a node, you need to pass K3S_URL and K3S_TOKEN or K3S_CLUSTER_SECRET as environment variables. For example:

Curl-sfL https://get.k3s.io | K3Selecurl = https://myserver:6443 K3S_TOKEN=XXX sh-1.2Manual installation

Download K3s-the latest version, x86x64, supported by ARMv7 and ARM64.

Run the server:

Sudo K3s server & # Kubeconfig is written to / etc/rancher/k3s/k3s.yamlsudo K3s kubectl get node# On a different node run the below. NODE_TOKEN comes from / var/lib/rancher/k3s/server/node-token# on your serversudo K3s agent-- server https://myserver:6443-- token ${NODE_TOKEN} 1.3 High availability Mode

Starting with v1.0.0, K3s predictability supports highly available control plane without the need for an external database. This means that there is no need to manage external etcd or SQL datastore to provide highly reliable production-level installations. This feature is still the experience state, and we hope to be the main architecture of HA K3s clusters in the future.

The architecture is implemented by embedding dqlite database into the K3s server process. DQLite means "distributed SQLite." According to https://dqlite.io, "a fast, embedded, persistent SQL database with Raft consensus that is perfect for fault-tolerant IoT and Edge devices." This is perfect for K3s.

For K3s to run in this mode, you need an odd number of server nodes, and it is recommended to start with three nodes.

To start, start server node first, using the cluster-init parameter to enable clustering and token, which will be used to share secret so that other server nodes can join the cluster.

K3S_TOKEN=SECRET K3s server-- cluster-init

After starting the first server, add the second / third server, which requires shared secret:

K3S_TOKEN=SECRET K3s server-- server https://:6443

Now that you have a highly available control plane service, add additional worker nodes to the cluster, just like adding a single server cluster.

Reference: https://rancher.com/docs/k3s/latest/en/installation/ha-embedded/

2. Use K3s

The kubeconfig file is used to configure access to the Kubernetes cluster cluster. It needs to be set up correctly and be able to access Kubernetes API, such as kubectl, to install applications and support Helm. The way to set kubeconfig includes the environment variable KUBECONFIG to support kubectl and helm. For example:

Export KUBECONFIG=/etc/rancher/k3s/k3s.yamlkubectl get pods-all-namespaceshelm ls-all-namespaces

Or indicate the location of the kubeconfig file in each command.

Kubectl-- kubeconfig / etc/rancher/k3s/k3s.yaml get pods-- all-namespaceshelm-- kubeconfig / etc/rancher/k3s/k3s.yaml ls-- access outside the all-namespaces cluster via kubectl

Copy / etc/rancher/k3s/k3s.yaml to your machine to ~ / .kube/config. Then replace "localhost" with the name of IP or K3s server. Kubectl is now able to manage the established K3s cluster.

3. K3s upgrade

You can upgrade K3s through the installation script or install the new binary version manually.

⚠️ Note: upgrade server nodes first, and then upgrade other work nodes.

Upgrade K3s through installation script

To upgrade from the old version to the new K3s, rerun the installation script, for example:

Curl-sfL https://get.k3s.io | sh-

Upgrade to the established version, using the following command (where vX.Y.Z is the specified version number):

Curl-sfL https://get.k3s.io | INSTALL_K3S_VERSION=vX.Y.Z-rc1 sh-manually upgrade K3s (Using the Binary)

Manually upgrade K3s:

Download the desired K3s version from here: releases

Install to the appropriate location (usually / usr/local/bin/k3s)

Stop the old version.

Start the new version.

Restart K3s

Restart K3s supports systemd and openrc.

Restart systemd manually using:

Sudo systemctl restart k3s

Restart openrc manually using:

Sudo service K3s restart4, build arm version image

The CPU instruction set of arm images is different from x86, so containers cannot cross-run to heterogeneous hardware environments (unlike virtual machines, which can provide instruction set simulation).

However, because the container engine provides a unified storage system, arm images and x86 images can use the same container image repository, which can be identified by the built-in tag. You must select the appropriate image version when using it, or you can use the same Dockerfile to package the container image version available for multiple architectures.

Reference:

Docker Desktop builds arm container image of Multi-Arch

After reading this, the article "what is the rapid deployment and use of K3s" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report