Create Namespace - revant/xkcd-proxy-monorepo GitHub Wiki

kubectl create namespace manish      (manish is namespace name)

Create file access.yaml : add that following

  ---
  apiVersion: v1
  kind: ServiceAccount
  metadata:
    name: manish-user
    namespace: manish

  ---
  kind: Role
  apiVersion: rbac.authorization.k8s.io/v1beta1
  metadata:
    name: manish-user-full-access
    namespace: manish
  rules:
  - apiGroups: ["", "extensions", "apps","networking.k8s.io", "rbac.authorization.k8s.io", "policy"]
    resources: ["*"]
    verbs: ["*"]
  - apiGroups: ["batch"]
    resources:
    - jobs
    - cronjobs
    verbs: ["*"]

  ---
  kind: RoleBinding
  apiVersion: rbac.authorization.k8s.io/v1beta1
  metadata:
    name: manish-user-view
    namespace: manish
  subjects:
  - kind: ServiceAccount
    name: manish-user
    namespace: manish
  roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: Role
    name: manish-user-full-access
kubectl create -f access.yaml

Get Secrets:

kubectl describe sa manish-user -n manish

Get the User Token:

 kubectl get secret manish-user-token-xxxxx -n manish -o "jsonpath={.data.token}" | base64 -d                        

Get the Certificate:

kubectl get secret manish-user-token-xxxxx -n manish -o "jsonpath={.data['ca\.crt']}"

create file manish-config.yaml add that following:

#manish-config.yaml
apiVersion: v1
kind: Config
preferences: {}

# Define the cluster
clusters:
- cluster:
    certificate-authority-data: PLACE CERTIFICATE HERE
    # You'll need the API endpoint of your Cluster here:
    server: https://YOUR_KUBERNETES_API_ENDPOINT
  name: my-cluster

# Define the user
users:
- name: manish-user
  user:
    as-user-extra: {}
    client-key-data: PLACE CERTIFICATE HERE
    token: PLACE USER TOKEN HERE

# Define the context: linking a user to a cluster
contexts:
- context:
    cluster: my-cluster
    namespace: manish
    user: manish-user
  name: manish

# Define current context
current-context: manish

Pack Config for gitlab / CI

 cat manish-config.yaml | base64         
cat manish-config.yaml | base64 >> text.txt
  save into text file
 cat text.txt 
k get namespaces