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

How to use K3s Kubernetes cluster for GitLab project

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces how to use K3s Kubernetes cluster for GitLab project, it has certain reference value, interested friends can refer to it, I hope you can learn a lot after reading this article, let the editor take you to know it.

TL;DR

K3s is a lightweight Kubernetes distribution (less than 40 MB) that is very easy to install and requires only 512 MB RAM. Perfect for IoT devices, edge computing, and running CI tasks. In this article, I will create a K3s cluster and show you how to integrate it into a GitLab project.

About K3s

K3s is a lightweight Kubernetes distribution developed by Rancher Labs.

It uses the lowest system requirements as a Kubernetes certified distribution:

Linux 3.10 +

521 MB ram per server

75 MB ram per node

200 MB disk space

X86_64,ARMv7,ARM64

This makes K3s very suitable for things related to IoT.

Create a project in GitLab

Before installing K3s, let's create a new project called _ api_ on GitLab.

After the creation is complete, we go to the _ Operation_ > _ Kubernetes_ menu.

Here we have two options:

We can create a Kubernetes cluster on GKE (Google Kubernetes Engine).

We can import the configuration of an existing Kubernetes cluster (no matter where it was created).

* * Note: * * with the latest version of GitLab, new clusters can only be created in GKE. GitLab, are there any other Kubernetes providers (AKS, EKS, DOKS … ) what about the plan to create a cluster? :)

We chose to add an existing cluster tab.

From here we can see that we need to fill in several fields of configuration information to provide to the cluster that needs to be integrated. Let's keep this page open and create a Kubernetes cluster first.

Create a K3s cluster

We are going to initialize a Kubernetes based on K3s. Why K3s? Because I want to show how easy it is to set it up. For simplicity, we only set up a single-node cluster.

I have configured a Ubuntu 18.04 server named _ node1_. When we start a shell program on the host, we only need to run the following command to install K3s, a Kubernetes-certified cluster. Really!

Root@node1:~ $curl-sfL [https://get.k3s.io](https://get.k3s.io/) | sh-

The above command is similar to the quick installation of Docker: curl [https://get.docker.com](https://get.docker.com/) | sh

After the installation is complete (really quickly), the configuration file used to connect to the cluster will be obtained in / etc/rancher/k3s/k3s.yaml.

* * root@node1:~ $cat / etc/rancher/k3s/k3s.yaml * * apiVersion: v1 clusters:-cluster: certificate-authority-data: LS0tL...tCg== server: https://localhost:6443 name: default contexts:-context: cluster: default user: default name: default current-context: default kind: Config preferences: {} users:-name: default user: password: 48f4b...4b4e7 username: admin

The local kubectl is automatically configured to try the configuration.

$kubectl get nodes NAME STATUS ROLES AGE VERSION node1 Ready master 3m v1.14.5-k3s.1

Note: it will be very easy to add additional nodes when we refer to the quick start at the end of the article. It simply takes a token from the primary node _ / var/lib/rancher/k3s/server/node-token_ and joins the other nodes using the following command:

$curl-sfL [https://get.k3s.io](https://get.k3s.io/) | K3Selecurl = https://myserver:6443 K3S_TOKEN=XXX sh-integrate into GitLab

Now we want to gather all the information about integrating the K3s cluster into our GitLab project.

Cluster name

We named it * k3s*.

URL of API Server

In the configuration file, API Server specifies https://localhost:6443. To get it from the outside, we need to provide the external IP address of _ node1_.

CA authentication of cluster

To provide cluster-to-GitLab CA authentication, we need to decode the certificate specified in the configuration (it is encoded in base64).

$kubectl config view-- raw\-- obsolete jsonpathpaths'{.cluster.certificate-authority-data}'\ | base64-- decode

Service token

The process of obtaining an identity token involves several steps. First, you need to create a ServiceAccount and provide it with the cluster-admin role. You can do this with the following command:

$cat

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