- name: 准备kubectl使用的admin证书签名请求 template: src=admin-csr.json.j2 dest={{ cluster_dir }}/ssl/admin-csr.json - name: 创建admin证书与私钥 shell: "cd {{ cluster_dir }}/ssl && {{ base_dir }}/bin/cfssl gencert \ -ca=ca.pem \ -ca-key=ca-key.pem \ -config=ca-config.json \ -profile=kubernetes admin-csr.json | {{ base_dir }}/bin/cfssljson -bare admin" - name: 设置集群参数 shell: "{{ base_dir }}/bin/kubectl config set-cluster {{ CLUSTER_NAME }} \ --certificate-authority={{ cluster_dir }}/ssl/ca.pem \ --embed-certs=true \ --server={{ KUBE_APISERVER }} \ --kubeconfig={{ cluster_dir }}/kubectl.kubeconfig" - name: 设置客户端认证参数 shell: "{{ base_dir }}/bin/kubectl config set-credentials admin \ --client-certificate={{ cluster_dir }}/ssl/admin.pem \ --embed-certs=true \ --client-key={{ cluster_dir }}/ssl/admin-key.pem \ --kubeconfig={{ cluster_dir }}/kubectl.kubeconfig" - name: 设置上下文参数 shell: "{{ base_dir }}/bin/kubectl config set-context {{ CONTEXT_NAME }} \ --cluster={{ CLUSTER_NAME }} --user=admin \ --kubeconfig={{ cluster_dir }}/kubectl.kubeconfig" - name: 选择默认上下文 shell: "{{ base_dir }}/bin/kubectl config use-context {{ CONTEXT_NAME }} \ --kubeconfig={{ cluster_dir }}/kubectl.kubeconfig" - name: 安装kubeconfig copy: src={{ cluster_dir }}/kubectl.kubeconfig dest=~/.kube/config