# Provisioning a CA and Generating TLS Certificates In this lab you will provision a [PKI Infrastructure](https://en.wikipedia.org/wiki/Public_key_infrastructure) using CloudFlare's PKI toolkit, [cfssl](https://github.com/cloudflare/cfssl), then use it to bootstrap a Certificate Authority, and generate TLS certificates for the following components: etcd, kube-apiserver, kube-controller-manager, kube-scheduler, kubelet, and kube-proxy. ## Certificate Authority In this section you will provision a Certificate Authority that can be used to generate additional TLS certificates. Generate the CA configuration file, certificate, and private key: ``` { cat > ca-config.json < ca-csr.json < admin-csr.json <`. In this section you will create a certificate for each Kubernetes worker node that meets the Node Authorizer requirements. Generate a certificate and private key for each Kubernetes worker node:
GCP ``` for instance in worker-0 worker-1 worker-2; do cat > ${instance}-csr.json <
AWS ``` VPC_ID="$(aws ec2 describe-vpcs \ --filters Name=tag-key,Values=kubernetes.io/cluster/kubernetes-the-hard-way \ --profile kubernetes-the-hard-way \ --query 'Vpcs[0].VpcId' \ --output text)" ``` ``` for i in 0 1 2; do instance="worker-$i" hostname="ip-10-240-0-2$i" cut -c3- >"$instance-csr.json" <

Results: ``` worker-0-key.pem worker-0.pem worker-1-key.pem worker-1.pem worker-2-key.pem worker-2.pem ``` ### The Controller Manager Client Certificate Generate the `kube-controller-manager` client certificate and private key: ``` { cat > kube-controller-manager-csr.json < kube-proxy-csr.json < kube-scheduler-csr.json < GCP ``` { KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way \ --region $(gcloud config get-value compute/region) \ --format 'value(address)') cat > kubernetes-csr.json <
AWS ``` KUBERNETES_PUBLIC_ADDRESS="$(aws elb describe-load-balancers \ --load-balancer-name kubernetes-the-hard-way \ --profile kubernetes-the-hard-way \ --query 'LoadBalancerDescriptions[0].DNSName' \ --output text)" cat >kubernetes-csr.json <

Results: ``` kubernetes-key.pem kubernetes.pem ``` ## The Service Account Key Pair The Kubernetes Controller Manager leverages a key pair to generate and sign service account tokens as describe in the [managing service accounts](https://kubernetes.io/docs/admin/service-accounts-admin/) documentation. Generate the `service-account` certificate and private key: ``` { cat > service-account-csr.json < GCP ``` for instance in worker-0 worker-1 worker-2; do gcloud compute scp ca.pem ${instance}-key.pem ${instance}.pem ${instance}:~/ done ```
AWS ``` get_ip() { aws ec2 describe-instances \ --filters \ Name=vpc-id,Values="$VPC_ID" \ Name=tag:Name,Values="$1" \ --profile kubernetes-the-hard-way \ --query 'Reservations[0].Instances[0].PublicIpAddress' \ --output text } ``` ``` for instance in worker-0 worker-1 worker-2; do scp -i ~/.ssh/kubernetes-the-hard-way -o StrictHostKeyChecking=no \ ca.pem "$instance-key.pem" "$instance.pem" "ubuntu@$(get_ip "$instance"):~/" done ```

Copy the appropriate certificates and private keys to each controller instance:
GCP ``` for instance in controller-0 controller-1 controller-2; do gcloud compute scp ca.pem ca-key.pem kubernetes-key.pem kubernetes.pem \ service-account-key.pem service-account.pem ${instance}:~/ done ```
AWS ``` for instance in controller-0 controller-1 controller-2; do scp -i ~/.ssh/kubernetes-the-hard-way -o StrictHostKeyChecking=no \ ca.pem ca-key.pem kubernetes-key.pem kubernetes.pem service-account-key.pem service-account.pem \ "ubuntu@$(get_ip "$instance"):~/" done ```

> The `kube-proxy`, `kube-controller-manager`, `kube-scheduler`, and `kubelet` client certificates will be used to generate client authentication configuration files in the next lab. Next: [Generating Kubernetes Configuration Files for Authentication](05-kubernetes-configuration-files.md)