Featured image of post Ubuntu-service-2024使用k3s搭建kubernetes

Ubuntu-service-2024使用k3s搭建kubernetes

Ubuntu-service-2024使用k3s搭建kubernetes

Ubuntu-service-2024使用k3s搭建kubernetesk3s

安装&使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 国内镜像源安装
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - \
--system-default-registry "registry.cn-hangzhou.aliyuncs.com"

# 卸载
sudo k3s-uninstall.sh

# 检查, 要多等一会
kubectl get nodes
kubectl get pod -A # 查看是不是都是 0/1, 如果只有1个就没问题

# docker镜像导出为 tar文件, 要确保导出前的镜像可用
docker save test -o test.tar
# 导入 ctr , 这样 kubenetes 就可以用本地镜像了
sudo k3s ctr image import test.tar
# 查看 ctr 里的镜像
sudo k3s ctr image list

# 启动并公开服务给集群外部访问
# 命令创建 deployment, --port 表示deploy服务端口为80
sudo kubectl create deployment nginx --image=base_images/base_nginx --port 80
# 查看
sudo kubectl get all
# 启动service , 类型为 NodePort, --target-port=80 是deploy服务所在端口, --node-port=30080就是service对集群外提供服务的端口
sudo kubectl expose deployment base-nginx --type=NodePort --port=80 --target-port=80 --name=base-nginx-service --node-port=30080
# 查看
sudo kubectl get all

# 启动完,可能 netstat 查看不到 service 监听的端口, 但是可以正常访问
sudo kubectl get svc -o wide

使用 Hugo 构建
主题 StackJimmy 设计