6. sealos 管理
6.1 部署应用
安装各种分布式应用 sealos run labring/helm:v3.8.2 # install helm sealos run labring/openebs:v1.9.0 # install openebs sealos run labring/minio-operator:v4.4.16 labring/ingress-nginx:4.1.0 \ labring/mysql-operator:8.0.23-14.1 labring/redis-operator:3.1.4 # oneliner
6.2 构建镜像
这里展示了如何用 helm 构建一个 nginx-ingress
集群镜像。
6.2.1 下载 helm chart
$ mkdir ingress-nginx && cd ingress-nginx $ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx $ helm pull ingress-nginx/ingress-nginx
随后就能找到下载的 chart:
$ ls ingress-nginx-4.3.0.tgz
6.2.2 添加镜像列表
sealos
会下载镜像列表中的镜像并缓存到 registry
目录。
目录必须形如 images/shim/[your image list filename]
:
$ ls /var/lib/sealos/data/default/rootfs/images/shim/ calicoImages DefaultImageList LvscareImageList $ cat /var/lib/sealos/data/default/rootfs/images/shim/DefaultImageList registry.k8s.io/kube-apiserver:v1.25.0 registry.k8s.io/kube-controller-manager:v1.25.0 registry.k8s.io/kube-scheduler:v1.25.0 registry.k8s.io/kube-proxy:v1.25.0 registry.k8s.io/pause:3.8 registry.k8s.io/etcd:3.5.4-0 registry.k8s.io/coredns/coredns:v1.9.3 $ cat /var/lib/sealos/data/default/rootfs/images/shim/calicoImages docker.io/calico/apiserver:v3.24.1 docker.io/calico/cni:v3.24.1 docker.io/calico/csi:v3.24.1 docker.io/calico/ctl:v3.24.1 docker.io/calico/dikastes:v3.24.1 docker.io/calico/kube-controllers:v3.24.1 docker.io/calico/node-driver-registrar:v3.24.1 docker.io/calico/node:v3.24.1 docker.io/calico/pod2daemon-flexvol:v3.24.1 docker.io/calico/typha:v3.24.1 $ vim /var/lib/sealos/data/default/rootfs/images/shim/nginxImages k8s.gcr.io/ingress-nginx/controller:v1.2.0 k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
6.2.3 编写 Dockerfile
FROM scratch COPY ingress-nginx-4.3.0.tgz . CMD ["helm install ingress-nginx ingress-nginx-4.3.0.tgz --namespace ingress-nginx --create-namespace"]
6.2.4 定制应用镜像
镜像名格式:docker.io/<dockerhub_name>/<image_name>:<version>
$ sealos build -f Dockerfile -t docker.io/ghostwritten/ingress-nginx:v1.2.0 .
output:
2022-10-14T16:30:08 info lookup in path charts 2022-10-14T16:30:08 info path charts is not exists, skip 2022-10-14T16:30:08 warn if you access private registry,you must be 'sealos login' or 'buildah login' 2022-10-14T16:30:08 info pull images [] for platform is linux/amd64 2022-10-14T16:30:08 info output images [] for platform is linux/amd64 STEP 1/3: FROM scratch STEP 2/3: COPY ingress-nginx-4.3.0.tgz . STEP 3/3: CMD ["helm install ingress-nginx ingress-nginx-4.3.0.tgz --namespace ingress-nginx --create-namespace"] COMMIT docker.io/ghostwritten/ingress-nginx:v1.2.0 Getting image source signatures Copying blob ccfa5df3b9eb done Copying config 76dea8608c done Writing manifest to image destination Storing signatures --> 76dea8608c7 [Warning] one or more build args were not consumed: [TARGETARCH TARGETOS TARGETPLATFORM] Successfully tagged docker.io/ghostwritten/ingress-nginx:v1.2.0 76dea8608c7a9edf375c293b4d5edb0f3e516f0c74016ee0dd0f3ffa5c179a02 2022-10-14T16:30:13 info ___ ___ ___ ___ ___ ___ /\ \ /\ \ /\ \ /\__\ /\ \ /\ \ /::\ \ /::\ \ /::\ \ /:/ / /::\ \ /::\ \ /:/\ \ \ /:/\:\ \ /:/\:\ \ /:/ / /:/\:\ \ /:/\ \ \ _\:\~\ \ \ /::\~\:\ \ /::\~\:\ \ /:/ / /:/ \:\ \ _\:\~\ \ \ /\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/ /:/__/ \:\__\ /\ \:\ \ \__\ \:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/ / \:\ \ \:\ \ /:/ / \:\ \:\ \/__/ \:\ \:\__\ \:\ \:\__\ \::/ / \:\ \ \:\ /:/ / \:\ \:\__\ \:\/:/ / \:\ \/__/ /:/ / \:\ \ \:\/:/ / \:\/:/ / \::/ / \:\__\ /:/ / \:\__\ \::/ / \::/ / \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ Website :https://www.sealos.io/ Address :github.com/labring/sealos
sealos 在构建的时候会自动添加镜像列表中的镜像依赖到集群镜像中,通过神奇的方式保存了里面依赖的 Docker 镜像。 并且在到别的环境中运行的时候更神奇的自动检测集群中想是否的 Docker 镜像,有的话自动下载,没有的话才会去 k8s.gcr.io 下载。 用户无需修改 helm chart 中的 docker 镜像地址,这里用到了镜像缓存代理的黑科技。
6.2.5 推送到镜像至 registry
$ sealos login docker.io -u ghostwritten -p <xxxx> Login Succeeded! $ sealos push docker.io/ghostwritten/ingress-nginx:v1.2.0
output:
Getting image source signatures Copying blob 5890fd8f0df3 done Copying config 76dea8608c done Writing manifest to image destination Storing signatures
6.2.6 运行集群镜像
$ sealos run docker.io/ghostwritten/ingress-nginx:v1.2.0
6.3 增加节点
6.3.1 增加 node 节点
$ sealos add --nodes 192.168.64.21,192.168.64.19
6.3.2 增加 master 节点
$ sealos add --masters 192.168.64.21,192.168.64.19
6.4 删除节点
6.4.1 删除 node 节点
$ sealos delete --nodes 192.168.64.21,192.168.64.19
6.4.2 删除 master 节点
$ sealos delete --masters 192.168.64.21,192.168.64.19
6.5 清理集群
$ sealos reset
参考: