I installed kubernetes
use kubeadm
and the kube-apiserver
started successfully. My computer’s operating system is Centos 7. Command like these:
kube-apiserver
--advertise-address=10.211.55.9
--allow-privileged=true
--authorization-mode=Node,RBAC
--client-ca-file=/etc/kubernetes/pki/ca.crt
--enable-admission-plugins=NodeRestriction
--enable-bootstrap-token-auth=true
--etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
--etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
--etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
--etcd-servers=https://127.0.0.1:2379
--insecure-port=0
--kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
--kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
--kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
--proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
--proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
--requestheader-allowed-names=front-proxy-client
--requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
--requestheader-extra-headers-prefix=X-Remote-Extra-
--requestheader-group-headers=X-Remote-Group
--requestheader-username-headers=X-Remote-User
--secure-port=6443
--service-account-key-file=/etc/kubernetes/pki/sa.pub
--service-cluster-ip-range=10.96.0.0/12
--tls-cert-file=/etc/kubernetes/pki/apiserver.crt
--tls-private-key-file=/etc/kubernetes/pki/apiserver.key
--enable-swagger-ui=true
--insecure-bind-address=0.0.0.0
--insecure-port=8080
open web browser and search http://localhost:8080/swagger-ui/
, I got the uri list without swagger ui. How to show swagger ui?
http://localhost:8080/swagger-ui/
{
"paths": [
"/apis",
"/apis/",
"/apis/apiextensions.k8s.io",
"/apis/apiextensions.k8s.io/v1",
"/apis/apiextensions.k8s.io/v1beta1",
"/healthz",
"/healthz/etcd",
"/healthz/log",
"/healthz/ping",
"/healthz/poststarthook/crd-informer-synced",
"/healthz/poststarthook/generic-apiserver-start-informers",
"/healthz/poststarthook/start-apiextensions-controllers",
"/healthz/poststarthook/start-apiextensions-informers",
"/livez",
"/livez/etcd",
"/livez/log",
"/livez/ping",
"/livez/poststarthook/crd-informer-synced",
"/livez/poststarthook/generic-apiserver-start-informers",
"/livez/poststarthook/start-apiextensions-controllers",
"/livez/poststarthook/start-apiextensions-informers",
"/metrics",
"/openapi/v2",
"/readyz",
"/readyz/etcd",
"/readyz/log",
"/readyz/ping",
"/readyz/poststarthook/crd-informer-synced",
"/readyz/poststarthook/generic-apiserver-start-informers",
"/readyz/poststarthook/start-apiextensions-controllers",
"/readyz/poststarthook/start-apiextensions-informers",
"/readyz/shutdown",
"/version"
]
}
4
Answers
The Kubernetes API server serves an OpenAPI spec via the
/openapi/v2
endpoint. So you can usehttp://localhost:8080/openapi/v2
Open a reverse proxy to your Kubernetes API server:
Save the Swagger file. Can’t link directly due to CORS policy.
Spin up a docker container with Swagger UI
Reference: https://jonnylangefeld.com/blog/kubernetes-how-to-view-swagger-ui
In case you would like to unleash the full potential of Swagger, this guide might help you: https://github.com/olivernadj/Kubernetes-REST-API-feat-Swagger-UI
The easiest way to get the openapi json is:
Now you can start a swagger-ui instance for that json like so:
Navigate to https://localhost:8081
You’ll see the swagger UI.
It’s pretty laggy though, because of the many APIs a Kubernetes cluster exposes.
Here is a quick way to play with swagger and k8s api.
Do not apply in prod.
cat tools/swagger/swagger.yml
Enjoy https://swagger-ui/
UPD:
if you see
Failed to load API definition
, open https://kubernetes/, click onProceed to kubernetes (unsafe)
and try again https://swagger-ui/.Otherwise make sure you follow the steps in order!
Cleaning:
k3d cluster delete