-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* minor updates * how to use as a sidecar for kubernetes dashboard
- Loading branch information
Showing
5 changed files
with
362 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
|
||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
--- | ||
|
||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard-csrf | ||
namespace: kubernetes-dashboard | ||
type: Opaque | ||
data: | ||
csrf: "" | ||
--- | ||
|
||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard-key-holder | ||
namespace: kubernetes-dashboard | ||
type: Opaque | ||
--- | ||
|
||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard-settings | ||
namespace: kubernetes-dashboard | ||
--- | ||
|
||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: kubernetes-dashboard | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-admin | ||
subjects: | ||
- kind: ServiceAccount | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
--- | ||
|
||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
k8s-app: kubernetes-dashboard | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
spec: | ||
containers: | ||
- name: ns-filter | ||
image: quay.io/clastix/capsule-ns-filter | ||
imagePullPolicy: Always | ||
command: | ||
- /capsule-ns-filter | ||
- --k8s-control-plane-url=https://kubernetes.default.svc | ||
- --capsule-user-group=capsule.clastix.io | ||
- --zap-devel | ||
- --zap-log-level=10 | ||
- --enable-ssl=true | ||
- --ssl-cert-path=/opt/certs/tls.crt | ||
- --ssl-key-path=/opt/certs/tls.key | ||
volumeMounts: | ||
- name: ns-filter-certs | ||
mountPath: /opt/certs | ||
ports: | ||
- containerPort: 9001 | ||
name: http | ||
protocol: TCP | ||
resources: | ||
- name: dashboard | ||
image: kubernetesui/dashboard:v2.0.4 | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 8443 | ||
protocol: TCP | ||
args: | ||
- --auto-generate-certificates | ||
- --namespace=cmp-system | ||
- --tls-cert-file=tls.crt | ||
- --tls-key-file=tls.key | ||
- --apiserver-host=https://localhost:9001 | ||
- --kubeconfig=/opt/.kube/config | ||
volumeMounts: | ||
- name: kubernetes-dashboard-certs | ||
mountPath: /certs | ||
- mountPath: /tmp | ||
name: tmp-volume | ||
- mountPath: /opt/.kube | ||
name: kubeconfig | ||
livenessProbe: | ||
httpGet: | ||
scheme: HTTPS | ||
path: / | ||
port: 8443 | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 30 | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
readOnlyRootFilesystem: true | ||
runAsUser: 1001 | ||
runAsGroup: 2001 | ||
volumes: | ||
- name: kubernetes-dashboard-certs | ||
secret: | ||
secretName: kubernetes-dashboard-certs | ||
- name: ns-filter-certs | ||
secret: | ||
secretName: ns-filter-certs | ||
- name: tmp-volume | ||
emptyDir: {} | ||
- name: kubeconfig | ||
configMap: | ||
defaultMode: 420 | ||
name: kubernetes-dashboard-kubeconfig | ||
serviceAccountName: kubernetes-dashboard | ||
--- | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kubernetes-dashboard-kubeconfig | ||
namespace: kubernetes-dashboard | ||
data: | ||
config: | | ||
kind: Config | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
insecure-skip-tls-verify: true | ||
server: https://localhost:9001 | ||
name: localhost | ||
contexts: | ||
- context: | ||
cluster: localhost | ||
user: kubernetes-admin | ||
name: admin@localhost | ||
current-context: admin@localhost | ||
preferences: {} | ||
users: | ||
- name: kubernetes-admin | ||
user: | ||
client-certificate-data: REDACTED | ||
client-key-data: REDACTED | ||
--- | ||
|
||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
labels: | ||
k8s-app: dashboard-metrics-scraper | ||
name: dashboard-metrics-scraper | ||
namespace: kubernetes-dashboard | ||
spec: | ||
ports: | ||
- port: 8000 | ||
targetPort: 8000 | ||
selector: | ||
k8s-app: dashboard-metrics-scraper | ||
--- | ||
|
||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
spec: | ||
ports: | ||
- port: 443 | ||
targetPort: 8443 | ||
selector: | ||
k8s-app: kubernetes-dashboard | ||
--- | ||
|
||
apiVersion: networking.k8s.io/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
annotations: | ||
ingress.kubernetes.io/ssl-passthrough: "true" | ||
ingress.kubernetes.io: ssl-redirect | ||
spec: | ||
rules: | ||
- host: dashboard.clastix.io | ||
http: | ||
paths: | ||
- backend: | ||
serviceName: kubernetes-dashboard | ||
servicePort: 443 | ||
path: / | ||
--- | ||
|
||
apiVersion: v1 | ||
data: | ||
tls.crt: REDACTED | ||
tls.key: REDACTED | ||
kind: Secret | ||
metadata: | ||
name: kubernetes-dashboard-certs | ||
namespace: kubernetes-dashboard | ||
type: Opaque | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
data: | ||
tls.crt: REDACTED | ||
tls.key: REDACTED | ||
kind: Secret | ||
metadata: | ||
name: ns-filter-certs | ||
namespace: kubernetes-dashboard | ||
type: Opaque |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Running capsule-ns-filter as sidecar container | ||
The `capsule-ns-filter` can be deployed as sidecar container for server-side Kubernetes dashboards. It will intercept all requests sent from the client side to the server-side of the dashboard and it will proxy them to the Kubernetes APIs server. | ||
|
||
``` | ||
capsule-ns-filter | ||
+------------+ | ||
|:9001 +--------+ | ||
+------------+ v | ||
+-----------+ | | +------------+ | ||
browser +------>+:443 +-------->+:8443 | |:6443 | | ||
+-----------+ +------------+ +------------+ | ||
ingress-controller dashboard kube-apiserver | ||
(ssl-passthrough) server-side backend | ||
``` | ||
|
||
The server-side backend of the dashboard must leave to specify the URL of the Kubernetes APIs server. For example the [sidecar-setup.yaml](../deploy/sidecar-setup.yaml) manifest contains an example for deploying with [Kubernetes Dashboard](https://github.com/kubernetes/dashboard), and the ingress controller in ssl-passthrough mode. | ||
|
||
Place the `capsule-ns-filter` in a pod with SSL mode, i.e. `--enable-ssl=true` and passing valid certificate and key files in a secret. | ||
|
||
```yaml | ||
... | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
spec: | ||
containers: | ||
- name: ns-filter | ||
image: quay.io/clastix/capsule-ns-filter | ||
imagePullPolicy: IfNotPresent | ||
command: | ||
- /capsule-ns-filter | ||
- --k8s-control-plane-url=https://kubernetes.default.svc | ||
- --capsule-user-group=capsule.clastix.io | ||
- --zap-log-level=5 | ||
- --enable-ssl=true | ||
- --ssl-cert-path=/opt/certs/tls.crt | ||
- --ssl-key-path=/opt/certs/tls.key | ||
volumeMounts: | ||
- name: ns-filter-certs | ||
mountPath: /opt/certs | ||
ports: | ||
- containerPort: 9001 | ||
name: http | ||
protocol: TCP | ||
... | ||
``` | ||
|
||
In the same pod, place the Kubernetes Dashboard in _"out-of-cluster"_ mode with `--apiserver-host=https://localhost:9001` to send all the requests to the `capsule-ns-filter` sidecar container: | ||
|
||
|
||
```yaml | ||
... | ||
- name: dashboard | ||
image: kubernetesui/dashboard:v2.0.4 | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 8443 | ||
protocol: TCP | ||
args: | ||
- --auto-generate-certificates | ||
- --namespace=cmp-system | ||
- --tls-cert-file=tls.crt | ||
- --tls-key-file=tls.key | ||
- --apiserver-host=https://localhost:9001 | ||
- --kubeconfig=/opt/.kube/config | ||
volumeMounts: | ||
- name: kubernetes-dashboard-certs | ||
mountPath: /certs | ||
- mountPath: /tmp | ||
name: tmp-volume | ||
- mountPath: /opt/.kube | ||
name: kubeconfig | ||
livenessProbe: | ||
httpGet: | ||
scheme: HTTPS | ||
path: / | ||
port: 8443 | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 30 | ||
... | ||
``` | ||
|
||
Make sure you pass a valid `kubeconfig` file to the dashboard pointing to the `capsule-ns-filter` sidecar container instead of the `kube-apiserver` directly: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kubernetes-dashboard-kubeconfig | ||
namespace: kubernetes-dashboard | ||
data: | ||
config: | | ||
kind: Config | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
insecure-skip-tls-verify: true | ||
server: https://localhost:9001 # <- point to the capsule-ns-filter | ||
name: localhost | ||
contexts: | ||
- context: | ||
cluster: localhost | ||
user: kubernetes-admin # <- dashboard has cluster-admin permissions | ||
name: admin@localhost | ||
current-context: admin@localhost | ||
preferences: {} | ||
users: | ||
- name: kubernetes-admin | ||
user: | ||
client-certificate-data: REDACTED | ||
client-key-data: REDACTED | ||
``` | ||
After starting the dashboard, login as a Tenant Owner user, e.g. `alice` according to the used authentication method, and check you can see only owned namespaces: | ||
|
||
![Dashboard UI namespace page](images/kubernetes-dashboard.png) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters