带有oauth令牌auth的python中的kubectl包装器
zalando-kubectl的Python项目详细描述
具有oauth令牌身份验证的python中的kubernetes cli(kubectl)包装器。
此包装器脚本zkubectl用作kubectl二进制文件的替换项:
- 它从google下载当前的kubectlbinary
- 它使用通过zign获得的oauth承载令牌生成一个新的~/.kube/config。
- 它将命令传递给kubectlbinary
安装
需要Python3.4+。
$ sudo pip3 install --upgrade zalando-kubectl
用法
您可以直接登录到已知的kubernetes api服务器端点:
$ zkubectl login https://my-api-server.example.org $ zkubectl cluster-info
您还可以将群集注册表配置为按ID查找群集:
$ zkubectl configure --cluster-registry=https://cluster-registry.example.org
$ zkubectl login my-cluster-id
群集注册表需要提供以下http api才能正常工作:
$ curl -H "Authorization: Bearer $(zign tok)" https://cluster-registry.example.org/kubernetes-clusters/my-cluster-id {"api_server_url": "https://my-api-server.example.org"}
另外还有一个方便的命令可以在浏览器中打开Kubernetes Dashboard web UI:
$ zkubectl dashboard Waiting forlocal kubectl proxy.. . . . . . . . . . .Starting to serve on 127.0.0.1:8001 OK Opening http://localhost:8001/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy ..
单元测试
使用tox运行单元测试:
$ sudo pip3 install tox $ tox
本地更改
建议为项目设置一个virtualenv。
转到项目目录并安装依赖项
$ cd <project-path>
$ pip install -r requirements.txt
$ pip install --editable .
现在,代码更改将只反映在zkubectl二进制文件中。
$ zkubectl <wahatever>