摘要:本文主要介绍介绍k3s的环境搭建和简单使用,使用的是最新版本,下面将以基于docker
作为容器来介绍安装步骤
一、基本环境准备
1 | bash复制代码#禁用**iptables**和**firewalld**服务 |
二、docker环境准备
1 | bash复制代码wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo |
三、k3s环境搭建(单机)
使用
k3s
默认容器安装命令如下curl -sfL https://get.k3s.io | sh -
使用
docker
容器安装命令如下curl -sfL https://get.k3s.io | sh -s - server --docker
安装完成后会显示如下的说明
如果想像使用
k8s
那样使用kubectl
命令,则需要创建软连接或者更新配置
1 | bash复制代码# 第一种方式 |
四、集群环境搭建 work
节点加入
查看master节点的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 -
到此环境就安装结束了,部署一个应用看看
五、部署demo
1 | yaml复制代码vim k8s-springboot.yaml |
页面访问
traefik
使用
Traefik is an open-source Edge Router that makes publishing your services a fun and easy experience. It receives requests on behalf of your system and finds out which components are responsible for handling them.(我人为这个和Ingress提供了相同的功能,作为外部服务访问的入口)
trace-dashboard
监控面板使用
- 删除原来的
trace-dashboard
运行
kubectl delete IngressRoute traefik-dashboard -n kube-system
删除后,我们需要创建一个新的traefik-dashboard
路径为:
/var/lib/rancher/k3s/server/manifests
文件名称:traefik-dashboard.yaml
不用执行,k3s
会自动扫描该文件下的文件进行自动更新
1 | yaml复制代码apiVersion: traefik.containo.us/v1alpha1 |
创建好后如下显示
kubectl get IngressRoute -A
页面访问http://traefik.local.huzhihui.com/dashboard/#/
我们之前创建了
springboot.yaml
的实例,现在先把该实例删除,运行kubectl delete -f springboot.yaml
创建新的
k8s-springboot.yaml
运行kubectl apply -f k8s-springboot.yaml
1 | yaml复制代码apiVersion: v1 |
浏览器访问
http://springboot-demo.local.huzhihui.com/
如果想通过默认的
traefik
通过路径前缀进行转发则需要按照如下配置
1 | yaml复制代码--- |
上面的配置你访问则和
nginx
配置的反向代理一样会截取/a
的路径,直接定位到实际的服务
Ingress
使用
如果觉得
IngressRoute
使用不太明了,也可以继续在traefik
中使用Ingress
新建文件
k3s-springboot-ingress.yaml
1 | yaml复制代码kind: Ingress |
本文转载自: 掘金