How to Add Users to Kubernetes (kubectl)?

后端 未结 3 1692
傲寒
傲寒 2020-12-22 17:59

I\'ve created a Kubernetes cluster on AWS with kops and can successfully administer it via kubectl from my local machine.

I can view the current config

3条回答
  •  执念已碎
    2020-12-22 18:39

    You say :

    I need to enable other users to also administer.

    But according to the documentation

    Normal users are assumed to be managed by an outside, independent service. An admin distributing private keys, a user store like Keystone or Google Accounts, even a file with a list of usernames and passwords. In this regard, Kubernetes does not have objects which represent normal user accounts. Regular users cannot be added to a cluster through an API call.

    You have to use a third party tool for this.

    == Edit ==

    One solution could be to manually create a user entry in the kubeconfig file. From the documentation :

    # create kubeconfig entry
    $ kubectl config set-cluster $CLUSTER_NICK \
        --server=https://1.1.1.1 \
        --certificate-authority=/path/to/apiserver/ca_file \
        --embed-certs=true \
        # Or if tls not needed, replace --certificate-authority and --embed-certs with
        --insecure-skip-tls-verify=true \
        --kubeconfig=/path/to/standalone/.kube/config
    
    # create user entry
    $ kubectl config set-credentials $USER_NICK \
        # bearer token credentials, generated on kube master
        --token=$token \
        # use either username|password or token, not both
        --username=$username \
        --password=$password \
        --client-certificate=/path/to/crt_file \
        --client-key=/path/to/key_file \
        --embed-certs=true \
        --kubeconfig=/path/to/standalone/.kube/config
    
    # create context entry
    $ kubectl config set-context $CONTEXT_NAME \
        --cluster=$CLUSTER_NICK \
        --user=$USER_NICK \
        --kubeconfig=/path/to/standalone/.kube/config
    

提交回复
热议问题