何为 serverless kubernetes

顾名思义,就是不须要装置间接关上网页就能够间接应用的 kubernetes,是一个多租户共享 kubernetes 的租户模型,这样做的益处是对于用户的应用老本极低,而且无需装置 kubernetes, 且天生对多租户的隔离性做的很好。
劣势是用户没有集群级别的管理权限,比方拜访节点,或者挂载主机目录,共享主机端口等,其实这也不是劣势,因为凋谢这些货色自身就是不平安的。

sealos 在这块做了十分多的优化,间接能做到在公网这种不可信的环境中让多租户平安的共享一个 kubernetes 集群,从而把 IT 老本打到骨折。

这是一个系列文章,咱们从 sealos 的一些根底性能开始介绍,本篇介绍的是 sealos 的 terminal 能力。

cloud terminal 应用教程

cloud terminal 是一个跑在容器内的 web terminal, terminal 中曾经配置好了用户的 .kube/config,
也蕴含了一些常用命令,简直能够用来拜访所有 sealos 曾经提供的利用的 API.

tips: 目前 terminal 中不反对长久化文件,请务必保留好在外面编辑的一些文件。

拜访 API server

terminal 中曾经装置 kubectl, 也配置好用户的 kubeconfig.

root@thpqxr0bh:~# kubectl get podNAME                                                             READY   STATUS    RESTARTS   AGEacid-test-0                                                      1/1     Running   0          37mterminal-8b66134e-5294-480f-b6c4-00243fc2488e-5cdc66697c-d5tss   1/1     Running   0          40m

查看 .kube/config

root@thpqxr0bh:~# cat .kube/config apiVersion: v1clusters:- cluster:    server: https://kubernetes.default.svc.cluster.local:443  name: kubernetescontexts:- context:    cluster: kubernetes    user: 8b66134e-5294-480f-b6c4-00243fc2488e    namespace: ns-8b66134e-5294-480f-b6c4-00243fc2488e  name: 8b66134e-5294-480f-b6c4-00243fc2488ecurrent-context: 8b66134e-5294-480f-b6c4-00243fc2488ekind: Configpreferences: {}users:- name: 8b66134e-5294-480f-b6c4-00243fc2488e  user:    token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjItUWxyLUc3X0FiNjF...

这里如果把 server 地址批改成 https://cloud.sealos.io:6443 就能够近程拜访 apiserver, 如应用你本地的 terminal,
或者集成到任意的 CI/CD 零碎中,只须要把文件内容拷贝到客户端的 ~/.kube/config 目录即可

权限管制

当你尝试越权行为时:

root@thpqxr0bh:~# kubectl get nodeError from server (Forbidden): nodes is forbidden: User "system:serviceaccount:user-system:8b66134e-5294-480f-b6c4-00243fc2488e" cannot list resource "nodes" in API group "" at the cluster scope

用户是没有权限拜访 node 的.

拜访其它资源

能够通过 terminal 拜访 数据库实例, 或者 sealos cloud provider 提供的多集群

root@thpqxr0bh:~# kubectl get infraNAME    STATUS    AGE     AZaaa     Running   3d23h   cn-north-1bfanux   Running   4d3h    cn-north-1btest    Running   13d     cn-north-1broot@thpqxr0bh:~# kubectl get clusterNAME    AGEaaa     3d23hfanux   4d3htest    13droot@thpqxr0bh:~# kubectl get infraNAME    STATUS    AGE     AZaaa     Running   3d23h   cn-north-1bfanux   Running   4d3h    cn-north-1btest    Running   13d     cn-north-1b

当然也能够删除或者编辑这些资源。

调试

terminal 还是十分好的调试工具,因为其本质也是运行在用户 ns 下的一个 pod,而且外面自带很多网络工具.

root@thpqxr0bh:~# nslookup acid-testServer:         10.96.0.10Address:        10.96.0.10#53Name:   acid-test.ns-8b66134e-5294-480f-b6c4-00243fc2488e.svc.cluster.localAddress: 10.96.2.134root@thpqxr0bh:~# ping 10.96.2.134PING 10.96.2.134 (10.96.2.134) 56(84) bytes of data.64 bytes from 10.96.2.134: icmp_seq=1 ttl=64 time=0.048 ms64 bytes from 10.96.2.134: icmp_seq=2 ttl=64 time=0.069 ms

甚至能够在 terminal 中写代码

root@thpqxr0bh:~# vim main.goroot@thpqxr0bh:~# go run main.go hello sealos!

sealos 以kubernetes为内核的云操作系统发行版,让云原生简略遍及

laf 写代码像写博客一样简略,什么docker kubernetes通通不关怀,我只关怀写业务!