There is a server at home, usually used as its own development environment, running some small programs. It is planned to upgrade the server and use k3s to manage common development tools, which is convenient for your own use. Because I only have one server, there is no cluster in this article.
Quick install command
## "-- Docker" uses Docker as a container < defau lt use containerd > ## "-- no deploy tracefik" means that the tracefik service is not used curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--docker --no-deploy traefik" sh -
Please refer to the following method to shut down the traifik service after startup. After that, we will use ingress as the direction agent service.
Turn off the default traifik service
## Enter k3s default startup orchestration directory cd /var/lib/rancher/k3s/server/manifests ## Rename the traefik choreography to prevent restart after shutdown mv traefik.yaml traefik.yaml_back ## View the running status of reverse agent service (traifik) kubectl get svc traefik --namespace kube-system -w kubectl describe svc traefik --namespace kube-system | grep Ingress | awk '{print $3}' //Prompt: it indicates that there is no traifik service in the current cluster, otherwise it needs to be deleted manually Error from server (NotFound): services "traefik" not found ## Delete traifik manually kubectl delete -f traefik.yaml ## Modify the configuration file of K3S service vim /etc/systemd/system/multi-user.target.wants/k3s.service ## Modify the value of ExecStart to: ExecStart=/usr/local/bin/k3s server --docker --no-deploy traefik
View startup node
### sudo kubectl get nodes root@MiWiFi-R1CM-srv:~# sudo kubectl get nodes NAME STATUS ROLES AGE VERSION miwifi-r1cm-srv Ready master 3d7h v1.17.3+k3s1
View basic service startup status
### kubectl -n kube-system get pods root@MiWiFi-R1CM-srv:~# kubectl -n kube-system get pods NAME READY STATUS RESTARTS AGE local-path-provisioner-58fb86bdfd-l8msw 1/1 Running 2 3d7h metrics-server-6d684c7b5-k8r9n 1/1 Running 1 3d7h coredns-d798c9dd-67mmc 1/1 Running 1 3d7h
Uninstall k3s
## Necessary for initial installation sh /usr/local/bin/k3s-uninstall.sh
Install ingress (reverse agent)
Documentation: https://gitee.com/doudoumaomao/free-cloud-deploy/tree/master/develop/k3s
You need to install the ingress controller first. When the service is started, it will automatically listen to port 80 and port 443.
Then start tomcat
apiVersion: apps/v1 kind: Deployment metadata: namespace: kube-public name: tomcat-service labels: app: tomcat-service spec: replicas: 1 selector: matchLabels: app: tomcat-service template: metadata: labels: app: tomcat-service spec: containers: - name: tomcat-service image: tomcat ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: namespace: kube-public name: tomcat-service spec: ports: - port: 8080 protocol: TCP selector: app: tomcat-service
Add reverse proxy:
apiVersion: extensions/v1beta1 kind: Ingress metadata: namespace: kube-public name: ingress-nginx spec: rules: - host: a1.free-js.com http: paths: - backend: serviceName: tomcat-service servicePort: 8080
View service startup
kubectl get svc --all-namespaces NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 3d9h kube-system kube-dns ClusterIP 10.43.0.10 <none> 53/UDP,53/TCP,9153/TCP 3d9h kube-system metrics-server ClusterIP 10.43.23.150 <none> 443/TCP 3d9h ingress-nginx ingress-nginx NodePort 10.43.103.187 <none> 80:30729/TCP,443:30338/TCP 4h47m kube-public tomcat-service ClusterIP 10.43.180.159 <none> 8080/TCP 169m
Modify the local hosts file to add domain name resolution. Convert address to server physical IP
## Test whether the reverse agent is successful. If a message "tomat" is prompted, it indicates that the agent is correct. curl http://a1.free-js.com
So far, k3s has been started normally, and some commonly used services will be arranged later.