- apply manifests
- run kubeconfiggen.sh
- use registry-cleaner.kubeconfig:
KUBECONFIG=/root/registry-cleaner.kubeconfig kubectl get pods -A
Last active
January 14, 2023 13:46
-
-
Save mrhalix/4a7475db467c62188ca09b2d26b0015f to your computer and use it in GitHub Desktop.
manifests and kubeconfig template to read-only access to pods on kubernetes
This file contains hidden or 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
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
annotations: | |
rbac.authorization.kubernetes.io/autoupdate: "true" | |
name: registry-cleaner-read-only | |
namespace: default | |
rules: | |
- apiGroups: [""] | |
resources: ["pods"] | |
verbs: ["get", "list"] |
This file contains hidden or 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
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: registry-cleaner-binding | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: ClusterRole | |
name: registry-cleaner-read-only | |
subjects: | |
- kind: ServiceAccount | |
name: registry-cleaner | |
namespace: default |
This file contains hidden or 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
ca=$(kubectl --context prod get secret registry-cleaner-secret -o jsonpath='{.data.ca\.crt}') | |
token=$(kubectl --context prod get secret registry-cleaner-secret -o jsonpath='{.data.token}' | base64 --decode) | |
namespace=$(kubectl --context prod get secret registry-cleaner-secret -o jsonpath='{.data.namespace}' | base64 --decode) | |
echo " | |
apiVersion: v1 | |
kind: Config | |
clusters: | |
- name: default-cluster | |
cluster: | |
certificate-authority-data: ${ca} | |
server: https://172.16.1.101:6443 | |
contexts: | |
- name: default-context | |
context: | |
cluster: default-cluster | |
namespace: default | |
user: default-user | |
current-context: default-context | |
users: | |
- name: default-user | |
user: | |
token: ${token} | |
" > registry-cleaner.kubeconfig |
This file contains hidden or 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
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: registry-cleaner-secret | |
annotations: | |
kubernetes.io/service-account.name: registry-cleaner | |
type: kubernetes.io/service-account-token |
This file contains hidden or 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
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: registry-cleaner | |
namespace: default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment