SpringBoot e-commerce project mall (40K + STAR) address: github.com/macrozheng/…

Abstract

Remember before using Minikube installation K8S, give points 3G memory is too small! Recently found that a K8S by the magnitude of K3S, the minimum 0.5g memory can be run, easy to install, and K8S with little difference. Recommend to everyone, I hope that more friends without high-end machines can also play K8S!

K3S profile

K3S is a fully Kubernetes compliant release. It can be installed using a single binary package (less than 100MB) and is easy to install with half the memory, running on as little as 0.5GB.

Why is it called K3S? The developers expect the K3S to have half the memory footprint of the K8S, a 10-letter word abbreviated as Kubernetes. So half the size is a five-letter word, or K3S.

The installation

It is very convenient to install using the script provided by the official, a command can complete the installation!

  • K3S is installed using a script, along with other utilities, includingkubectl,crictl,ctr,k3s-killall.shandk3s-uninstall.sh;
curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
Copy the code
  • After the installation is complete, the following information is displayed and K3S will be registered as a service in Linux.
Complete!
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
[INFO]  systemd: Starting k3s
Copy the code
  • You can view the running status of the service. The status isactive.
[root@linux-local k3s]# systemctl status k3sLow k3s. Service - Lightweight Kubernetes the Loaded: the Loaded (/ etc/systemd/system/k3s. Service; enabled; vendor preset: disabled) Active: active (running) since Thu 2021-01-28 10:18:39 CST; 2min 0s ago Docs: https://k3s.io Process: 14983 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS) Process: 14981 ExecStartPre=/sbin/modprobe br_netfilter (code=exited, status=0/SUCCESS) Main PID: 14986 (k3s-server) Tasks: 71 Memory: 776.3 MCopy the code

use

Using the kubectl command to operate K3S is no different from operating K8S in Minikube, this time creating a Deployment of Nginx and then exposing it to external access by creating a Service.

Create the cluster

  • Because K3S has kubectl installed by default, we can use it directly, for example, check the version number of Kubectl;
kubectl version
Copy the code
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"V1.20.2 + k3s1", GitCommit:"1d4adb0301b9a63ceec8cabb11b309e061f43d5f", GitTreeState:"clean", BuildDate:"2021-01-14T23:52:37Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"V1.20.2 + k3s1", GitCommit:"1d4adb0301b9a63ceec8cabb11b309e061f43d5f", GitTreeState:"clean", BuildDate:"2021-01-14T23:52:37Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Copy the code
  • You can also view cluster details.
kubectl cluster-info
Copy the code
Kubernetes control plane is running at https://127.0.0.1:6443 CoreDNS is running at The Metrics - https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy server is running the at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxyCopy the code
  • Looking at all the nodes in the cluster, you can see that K3S, like Minikube before it, creates a simple single-node cluster.
kubectl get nodes
Copy the code
NAME STATUS ROLES AGE VERSION Linux-local Ready Control-plane,master 11m V1.20.2 + K3S1Copy the code

The deployment of application

  • Specify the application image and create a Deployment, in this case an Nginx application;
Kubectl create deployment nginx-deployment --image=nginx:1.10Copy the code
  • View all Deployment;
kubectl get deployments
Copy the code
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   1/1     1            1           6s
Copy the code

Check the application

  • View Pod details, including IP addresses, occupied ports, and mirroring usage.
kubectl describe pods
Copy the code
Namespace: default Priority: 0 Node: linux-local/192.168.5.15 Start Time: nginx-deployment-597c48c9DD-j49BC Namespace: default Priority: 0 Node: linux-local/192.168.5.15 Start Time: Thu, 28 Jan 2021 10:53:14 +0800 Labels: app=nginx-deployment pod-template-hash=597c48c9dd Annotations: <none> Status: Controlled By: ReplicaSet/nginx-deployment-597c48c9dd Containers: nginx: The Container ID: containerd: / / 560 bbeefc9c5714b92ae9d0a1305c2b8746082f4aa11791a2b6e1f4288254ef0 Image: nginx: 1.10 the Image ID: docker.io/library/nginx@sha256:6202beb06ea61f44179e02ca965e8e13b961d12640101fca213efbfd145d7575 Port: <none> Host Port: <none> State: Running Started: Thu, 28 Jan 2021 10:53:16 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-fnrf7 (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-fnrf7: Type: Secret (a volume populated by a Secret) SecretName: default-token-fnrf7 Optional:false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  38s   default-scheduler  Successfully assigned default/nginx-deployment-597c48c9dd-j49bc to linux-local
  Normal  Pulled     38s   kubelet            Container image "Nginx: 1.10" already present on machine
  Normal  Created    38s   kubelet            Created container nginx
  Normal  Started    37s   kubelet            Started container nginx
Copy the code
  • Go inside the container and executebashCommand to exit the containerexitCommand.
kubectl exec -it nginx-deployment-597c48c9dd-j49bc -- bash
Copy the code

External access application

  • Create a Service to exposenginx-deploymentThe Deployment:
kubectl expose deployment/nginx-deployment --name="nginx-service" --type="NodePort" --port=80
Copy the code
  • View the status of all services.
kubectl get services
Copy the code
NAME TYPE cluster-ip external-ip PORT(S) AGE kubernetes ClusterIP 10.43.0.1 < None > 443/TCP 77m nginx-service NodePort 10.43.29.39 < none > 80:31494 / TCP 10 sCopy the code
  • To access the Nginx service, run the CURL command on the Linux server.
curl localhost:31494
Copy the code
  • Compared with Minikube installed in the virtual machine container application, K3S is installed directly on the local machine, directly open the firewall port can be accessed externally;
# open port
firewall-cmd --zone=public --add-port=31494/tcp --permanent
# restart firewall
firewall-cmd --reload
Copy the code
  • In external can access Nginx homepage, visit address: http://192.168.5.15:31494

conclusion

The K3S is a really good K8S distribution, not only easy to install, but also has a lower memory footprint. External access is also convenient because container applications are installed directly on the machine!

In this paper, making github.com/macrozheng/… Already included, welcome everyone Star!