sealos 神奇功能 serverless kubernetes 之 cloud terminal

何为 serverless kubernetes

顾名思义,就是不需要安装直接打开网页就可以直接使用的 kubernetes,是一个多租户共享 kubernetes 的租户模型,这样做的好处是对于用户的使用成本极低,而且无需安装 kubernetes, 且天生对多租户的隔离性做的很好。 劣势是用户没有集群级别的管理权限,比如访问节点,或者挂载主机目录,共享主机端口等,其实这也不是劣势,因为开放这些东西本身就是不安全的。

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

这是一个系列文章,我们从 sealos 的一些基础功能开始介绍,本篇介绍的是 sealos 的 terminal 能力。

file

cloud terminal 使用教程

cloud terminal 是一个跑在容器内的 web terminal, terminal 中已经配置好了用户的 .kube/config, 也包含了一些常用命令,几乎可以用来访问所有 sealos 已经提供的应用的 API.

tips: 目前 terminal 中不支持持久化文件,请务必保存好在里面编辑的一些文件。

访问 API server

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

root@thpqxr0bh:~# kubectl get pod
NAME                                                             READY   STATUS    RESTARTS   AGE
acid-test-0                                                      1/1     Running   0          37m
terminal-8b66134e-5294-480f-b6c4-00243fc2488e-5cdc66697c-d5tss   1/1     Running   0          40m

查看 .kube/config

root@thpqxr0bh:~# cat .kube/config 
apiVersion: v1
clusters:
- cluster:
    server: https://kubernetes.default.svc.cluster.local:443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: 8b66134e-5294-480f-b6c4-00243fc2488e
    namespace: ns-8b66134e-5294-480f-b6c4-00243fc2488e
  name: 8b66134e-5294-480f-b6c4-00243fc2488e
current-context: 8b66134e-5294-480f-b6c4-00243fc2488e
kind: Config
preferences: {}
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 node
Error 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 infra
NAME    STATUS    AGE     AZ
aaa     Running   3d23h   cn-north-1b
fanux   Running   4d3h    cn-north-1b
test    Running   13d     cn-north-1b
root@thpqxr0bh:~# kubectl get cluster
NAME    AGE
aaa     3d23h
fanux   4d3h
test    13d
root@thpqxr0bh:~# kubectl get infra
NAME    STATUS    AGE     AZ
aaa     Running   3d23h   cn-north-1b
fanux   Running   4d3h    cn-north-1b
test    Running   13d     cn-north-1b

当然也可以删除或者编辑这些资源。

调试

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

root@thpqxr0bh:~# nslookup acid-test
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   acid-test.ns-8b66134e-5294-480f-b6c4-00243fc2488e.svc.cluster.local
Address: 10.96.2.134

root@thpqxr0bh:~# ping 10.96.2.134
PING 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 ms
64 bytes from 10.96.2.134: icmp_seq=2 ttl=64 time=0.069 ms

甚至可以在 terminal 中写代码

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

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

laf 写代码像写博客一样简单,什么docker kubernetes统统不关心,我只关心写业务!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值