k8s开启swagger-ui 开启api界面 curl k8s api (含django-k8s-api项目seal地址)
现在的版本默认只开启了6443安全端口,需要证书验证才能访问api,实现起来稍微有点麻烦,这里提供一个简单的方法。先来看看官方说明:Complete API details are documented using Swagger v1.2 and OpenAPI. The Kubernetes apiserver (aka “master”) exposes an API that can be
现在的版本默认只开启了6443安全端口,需要证书验证才能访问api,实现起来稍微有点麻烦,这里提供一个简单的方法。
先来看看官方说明:
Complete API details are documented using Swagger v1.2 and OpenAPI. The Kubernetes apiserver (aka “master”) exposes an API that can be used to retrieve the Swagger v1.2 Kubernetes API spec located at /swaggerapi. You can also enable a UI to browse the API documentation at /swagger-ui by passing the --enable-swagger-ui=true flag to apiserver.
这段话是说可以通过一个参数开启swagger-ui。
1、修改apiserver的配置,添加三个参数。
vim /etc/kubernetes/manifests/kube-apiserver.yaml
- –enable-swagger-ui=true
- –insecure-bind-address=0.0.0.0
- –insecure-port=8080
第一个是开启swagger-ui,另外两个是暴露非安全端口,亦即可以不用证书验证。
二 使用 token访问
curl k8s api
推荐阅读:https://www.cnblogs.com/zphqq/p/12968646.html
步骤1 创建 sa(就有绑定一个token,原理请参考文章:https://www.jianshu.com/p/892b0e469266),注意这里使用的是 默认的 ClusterRole 叫 cluster-admin 这个权限很大
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: dashboard-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
步骤2 获取 token和api接口地址 并赋值变量
TOKEN=$(kubectl describe secrets $(kubectl get secrets -n kube-system |grep admin |cut -f1 -d ' ') -n kube-system |grep -E '^token' |cut -f2 -d':'|tr -d '\t'|tr -d ' ')
APISERVER=$(kubectl config view |grep server|cut -f 2- -d ":" | tr -d " ")
访问
url -H "Authorization: Bearer $TOKEN" $APISERVER/api/v1/namespaces/default/pods/ --insecure
推荐github上 django访问k8s api的项目(含channel-websocket 登录pod 虽然又时候会失败)
git clone https://github.com/hequan2017/seal
如果是centos7启动项目的话 freeze要改一下
aioredis==1.2.0
alembic==0.9.10
amqp==2.4.2
aniso8601==3.0.2
anyjson==0.3.3
apache-airflow==1.10.3
argh==0.26.2
asgi-redis==1.1.0
asgiref==3.1.2
asn1crypto==0.24.0
async-timeout==3.0.1
attrs==19.1.0
autobahn==19.6.2
Automat==0.7.0
Babel==2.7.0
backcall==0.1.0
bcrypt==3.1.6
billiard==3.5.0.5
cachetools==3.1.1
celery==4.1.1
certifi==2018.11.29
cffi==1.12.3
channels==2.2.0
channels-redis==2.4.0
chardet==3.0.4
Click==7.0
colorama==0.4.1
configparser==3.5.3
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
croniter==0.3.30
cryptography==2.7
daphne==2.3.0
decorator==4.3.0
defusedxml==0.6.0
Deprecated==1.2.13
dill==0.2.9
Django==2.2.4
django-bootstrap3==11.0.0
django-bootstrap4==0.0.7
django-celery-beat==1.4.0
django-celery-results==1.0.4
django-cors-headers==2.5.2
django-crispy-forms==1.7.2
django-filter==2.1.0
django-pure-pagination==0.3.0
django-rest-swagger==2.2.0
django-simpleui==2.1.2.603
django-timezone-field==3.0
djangorestframework==3.9.2
docutils==0.14
dramatiq==1.5.0
Flask==1.0.4
Flask-Admin==1.5.3
Flask-AppBuilder==1.12.3
Flask-Babel==0.12.2
Flask-Caching==1.3.3
Flask-Login==0.4.1
Flask-OpenID==1.3.0
Flask-SQLAlchemy==2.5.1
flask-swagger==0.2.13
Flask-WTF==0.14.3
flower==0.9.3
funcsigs==1.0.0
future==0.16.0
gevent==1.4.0
gitdb2==2.0.5
GitPython==2.1.11
google-auth==1.6.3
graphene==2.1.3
graphene-django==2.2.0
graphql-core==2.1
graphql-relay==0.4.5
greenlet==0.4.15
gunicorn==19.9.0
hiredis==1.0.0
hyperlink==19.0.0
idna==2.8
incremental==17.5.0
ipython==6.4.0
ipython-genutils==0.2.0
iso8601==0.1.12
itsdangerous==1.1.0
itypes==1.1.0
jedi==0.12.0
Jinja2==2.10
json-merge-patch==0.2
jsonfield==2.0.2
kombu==4.4.0
kubernetes==9.0.0
lockfile==0.12.2
lxml==4.3.4
Mako==1.0.12
Markdown==2.6.11
MarkupSafe==1.1.1
msgpack==0.6.1
msgpack-python==0.5.6
mysqlclient==1.3.14
numpy==1.16.4
oauthlib==3.0.1
openapi-codec==1.3.2
ordereddict==1.1
pandas==0.24.2
paramiko==2.4.2
parso==0.2.1
pathtools==0.1.2
pendulum==1.4.4
pexpect==4.6.0
pickleshare==0.7.4
prettytable==0.7.2
prometheus-client==0.2.0
promise==2.2.1
prompt-toolkit==1.0.15
psutil==5.6.3
ptyprocess==0.5.2
pyasn1==0.4.5
pyasn1-modules==0.2.5
pycparser==2.19
Pygments==2.2.0
PyHamcrest==1.9.0
PyMySQL==0.9.3
PyNaCl==1.3.0
python-crontab==2.3.6
python-daemon==2.1.2
python-dateutil==2.8.0
python-editor==1.0.4
python3-openid==3.1.0
pytz==2018.4
pytzdata==2019.1
PyYAML==5.1
redis==4.0.2
requests==2.21.0
requests-oauthlib==1.2.0
rsa==4.0
Rx==1.6.1
setproctitle==1.1.10
simplegeneric==0.8.1
simplejson==3.16.0
singledispatch==3.4.0.3
six==1.11.0
smmap2==2.0.5
SQLAlchemy==1.2.19
sqlparse==0.3.0
tabulate==0.8.3
tenacity==4.12.0
text-unidecode==1.2
thrift==0.11.0
tornado==5.1.1
traitlets==4.3.2
Twisted==19.2.1
txaio==18.8.1
tzlocal==1.5.1
unicodecsv==0.14.1
uritemplate==3.0.0
urllib3==1.24.1
vine==1.3.0
watchdog==0.8.3
watchdog-gevent==0.1.0
wcwidth==0.1.7
websocket-client==0.56.0
Werkzeug==0.14.1
wrapt==1.13.3
WTForms==2.2.1
zope.deprecation==4.4.0
zope.interface==4.6.0
更多推荐
所有评论(0)