Abstract: This article mainly introduces the environment construction and simple use of K3S, using the latest version, the following will be based on docker as a container to introduce the installation steps

1. Basic environment preparation

Systemctl stop firewalld systemctl disable firewalld # Disable iptables Systemctl stop iptables systemctl disable iptables # Disable swap swapoff -a && sed -i '/ swap/s/^\(.*\)$/#\1/g' /etc/fstab **selinux** sed -i 's/enforcing/disabled/' /etc/selinux/configCopy the code

Ii. Docker environment preparation

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo yum list Docker - ce - showduplicates | sort - r # version installation specified yum install docker - ce - yum source 20.10.7 # add ali cloud, Cat <<EOF > /etc/dock/daemon. json {"registry-mirrors": [ "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "Https://docker.mirrors.ustc.edu.cn"]} EOF # start docker systemctl enable docker && systemctl start dockerCopy the code

3. K3s Environment construction (single machine)

Use k3s default container installation command curl – sfL https://get.k3s.io | sh – as follows

Use the docker container install the command is curl – sfL https://get.k3s.io | sh – s – server – the docker

After the installation is complete, the following information is displayed

If you want to use the kubectl command as with K8S, you need to create a soft connection

echo "alias kubectl='k3s kubectl'" >> /etc/profile
source /etc/profile
Copy the code

4. Cluster environment constructionworkNodes to join

Viewing the master node token(K3S_TOKEN)

cat /var/lib/rancher/k3s/server/node-token

curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX INSTALL_K3S_EXEC="--docker" sh -

The installation is complete in this environment, deploy an application and see

5. Deploy Demo

vim k8s-springboot.yaml apiVersion: v1 kind: Namespace metadata: name: k8s-springboot --- apiVersion: v1 kind: Service metadata: name: springboot-demo-nodeport namespace: k8s-springboot spec: type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 30001 selector: app: springboot-demo --- apiVersion: apps/v1 kind: Deployment metadata: name: springboot-demo namespace: k8s-springboot spec: selector: matchLabels: app: springboot-demo replicas: 1 template: metadata: labels: app: springboot-demo spec: containers: - name: springboot-demo image: Huzhihui/springboot: 1.0.0 ports: - containerPort: -f k8s-springboot.yamlCopy the code

Page access