From 4d187fa03814a71bebc27349df71fc875080f2cf Mon Sep 17 00:00:00 2001 From: Mike Stevenson Date: Tue, 10 Oct 2017 22:28:21 -0700 Subject: [PATCH] adding commands/scripts for windows Signed-off-by: Mike Stevenson --- docs/02-client-tools.md | 21 +++ docs/03-compute-resources.md | 81 +++++++++ docs/04-certificate-authority.md | 209 ++++++++++++++++++++++ docs/05-kubernetes-configuration-files.md | 70 ++++++++ docs/06-data-encryption-keys.md | 32 ++++ 5 files changed, 413 insertions(+) diff --git a/docs/02-client-tools.md b/docs/02-client-tools.md index 738b879..25ef8a1 100644 --- a/docs/02-client-tools.md +++ b/docs/02-client-tools.md @@ -44,6 +44,21 @@ sudo mv cfssl_linux-amd64 /usr/local/bin/cfssl sudo mv cfssljson_linux-amd64 /usr/local/bin/cfssljson ``` +### Windows + +``` +Invoke-WebRequest -Uri https://pkg.cfssl.org/R1.2/cfssl_windows-amd64.exe -OutFile cfssl.exe +``` + +``` +Invoke-WebRequest -Uri https://pkg.cfssl.org/R1.2/cfssljson_windows-amd64.exe -OutFile cfssljson.exe +``` + +Add the current directory to the path (this will not persist between sessions): +``` +$env:Path += ";$(Get-Location)" +``` + ### Verification Verify `cfssl` version 1.2.0 or higher is installed: @@ -94,6 +109,12 @@ chmod +x kubectl sudo mv kubectl /usr/local/bin/ ``` +### Windows + +``` +Invoke-WebRequest -Uri https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/windows/amd64/kubectl.exe -OutFile kubectl.exe +``` + ### Verification Verify `kubectl` version 1.8.0 or higher is installed: diff --git a/docs/03-compute-resources.md b/docs/03-compute-resources.md index d81202d..16801a5 100644 --- a/docs/03-compute-resources.md +++ b/docs/03-compute-resources.md @@ -24,18 +24,29 @@ A [subnet](https://cloud.google.com/compute/docs/vpc/#vpc_networks_and_subnets) Create the `kubernetes` subnet in the `kubernetes-the-hard-way` VPC network: +##### Linux & OS X ``` gcloud compute networks subnets create kubernetes \ --network kubernetes-the-hard-way \ --range 10.240.0.0/24 ``` +#### Windows + +``` +gcloud compute networks subnets create kubernetes ` + --network kubernetes-the-hard-way ` + --range 10.240.0.0/24 +``` + > The `10.240.0.0/24` IP address range can host up to 254 compute instances. ### Firewall Rules Create a firewall rule that allows internal communication across all protocols: +#### Linux & OS X + ``` gcloud compute firewall-rules create kubernetes-the-hard-way-allow-internal \ --allow tcp,udp,icmp \ @@ -43,8 +54,19 @@ gcloud compute firewall-rules create kubernetes-the-hard-way-allow-internal \ --source-ranges 10.240.0.0/24,10.200.0.0/16 ``` +#### Windows + +``` +gcloud compute firewall-rules create kubernetes-the-hard-way-allow-internal ` + --allow tcp,udp,icmp ` + --network kubernetes-the-hard-way ` + --source-ranges 10.240.0.0/24,10.200.0.0/16 +``` + Create a firewall rule that allows external SSH, ICMP, and HTTPS: +#### Linux & OS X + ``` gcloud compute firewall-rules create kubernetes-the-hard-way-allow-external \ --allow tcp:22,tcp:6443,icmp \ @@ -52,6 +74,15 @@ gcloud compute firewall-rules create kubernetes-the-hard-way-allow-external \ --source-ranges 0.0.0.0/0 ``` +#### Windows + +``` +gcloud compute firewall-rules create kubernetes-the-hard-way-allow-external ` + --allow tcp:22,tcp:6443,icmp ` + --network kubernetes-the-hard-way ` + --source-ranges 0.0.0.0/0 +``` + > An [external load balancer](https://cloud.google.com/compute/docs/load-balancing/network/) will be used to expose the Kubernetes API Servers to remote clients. List the firewall rules in the `kubernetes-the-hard-way` VPC network: @@ -72,11 +103,20 @@ kubernetes-the-hard-way-allow-internal kubernetes-the-hard-way INGRESS Allocate a static IP address that will be attached to the external load balancer fronting the Kubernetes API Servers: +#### Linux & OS X + ``` gcloud compute addresses create kubernetes-the-hard-way \ --region $(gcloud config get-value compute/region) ``` +#### Windows + +``` +gcloud compute addresses create kubernetes-the-hard-way ` + --region $(gcloud config get-value compute/region) +``` + Verify the `kubernetes-the-hard-way` static IP address was created in your default compute region: ``` @@ -98,6 +138,8 @@ The compute instances in this lab will be provisioned using [Ubuntu Server](http Create three compute instances which will host the Kubernetes control plane: +#### Linux & OS X + ``` for i in 0 1 2; do gcloud compute instances create controller-${i} \ @@ -114,6 +156,24 @@ for i in 0 1 2; do done ``` +#### Windows + +``` +@(0,1,2) | ForEach-Object { + gcloud compute instances create controller-$_ ` + --async ` + --boot-disk-size 200GB ` + --can-ip-forward ` + --image-family ubuntu-1604-lts ` + --image-project ubuntu-os-cloud ` + --machine-type n1-standard-1 ` + --private-network-ip 10.240.0.1$_ ` + --scopes compute-rw,storage-ro,service-management,service-control,logging-write,monitoring ` + --subnet kubernetes ` + --tags kubernetes-the-hard-way,controller +} +``` + ### Kubernetes Workers Each worker instance requires a pod subnet allocation from the Kubernetes cluster CIDR range. The pod subnet allocation will be used to configure container networking in a later exercise. The `pod-cidr` instance metadata will be used to expose pod subnet allocations to compute instances at runtime. @@ -122,6 +182,8 @@ Each worker instance requires a pod subnet allocation from the Kubernetes cluste Create three compute instances which will host the Kubernetes worker nodes: +#### Linux & OS X + ``` for i in 0 1 2; do gcloud compute instances create worker-${i} \ @@ -139,6 +201,25 @@ for i in 0 1 2; do done ``` +#### Windows + +``` +@(0,1,2) | ForEach-Object { + gcloud compute instances create worker-$_ \ + --async \ + --boot-disk-size 200GB \ + --can-ip-forward \ + --image-family ubuntu-1604-lts \ + --image-project ubuntu-os-cloud \ + --machine-type n1-standard-1 \ + --metadata pod-cidr=10.200.$_.0/24 \ + --private-network-ip 10.240.0.2$_ \ + --scopes compute-rw,storage-ro,service-management,service-control,logging-write,monitoring \ + --subnet kubernetes \ + --tags kubernetes-the-hard-way,worker +} +``` + ### Verification List the compute instances in your default compute zone: diff --git a/docs/04-certificate-authority.md b/docs/04-certificate-authority.md index 7229356..48c3c80 100644 --- a/docs/04-certificate-authority.md +++ b/docs/04-certificate-authority.md @@ -8,6 +8,7 @@ In this section you will provision a Certificate Authority that can be used to g Create the CA configuration file: +#### Linux & OS X ``` cat > ca-config.json < ca-config.json < ca-csr.json < ca-csr.json < admin-csr.json < admin-csr.json < ${instance}-csr.json < kube-proxy-csr.json < kube-proxy-csr.json < kubernetes-csr.json < kubernetes-csr.json < The `kube-proxy` 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) diff --git a/docs/05-kubernetes-configuration-files.md b/docs/05-kubernetes-configuration-files.md index 0b8974b..53743bf 100644 --- a/docs/05-kubernetes-configuration-files.md +++ b/docs/05-kubernetes-configuration-files.md @@ -14,18 +14,27 @@ Each kubeconfig requires a Kubernetes API Server to connect to. To support high Retrieve the `kubernetes-the-hard-way` static IP address: +#### Linux & OS X ``` KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way \ --region $(gcloud config get-value compute/region) \ --format 'value(address)') ``` +#### Windows +``` +$KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way ` + --region $(gcloud config get-value compute/region) ` + --format 'value(address)') +``` + ### The kubelet Kubernetes Configuration File When generating kubeconfig files for Kubelets the client certificate matching the Kubelet's node name must be used. This will ensure Kubelets are properly authorized by the Kubernetes [Node Authorizer](https://kubernetes.io/docs/admin/authorization/node/). Generate a kubeconfig file for each worker node: +#### Linux & OS X ``` for instance in worker-0 worker-1 worker-2; do kubectl config set-cluster kubernetes-the-hard-way \ @@ -49,6 +58,30 @@ for instance in worker-0 worker-1 worker-2; do done ``` +#### Windows +``` +@('worker-0','worker-1','worker-2') | ForEach-Object { + kubectl config set-cluster kubernetes-the-hard-way ` + --certificate-authority=ca.pem ` + --embed-certs=true ` + --server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443 ` + --kubeconfig=$_.kubeconfig + + kubectl config set-credentials system:node:$_ ` + --client-certificate=$_.pem ` + --client-key=$_-key.pem ` + --embed-certs=true ` + --kubeconfig=$_.kubeconfig + + kubectl config set-context default ` + --cluster=kubernetes-the-hard-way ` + --user=system:node:$_ ` + --kubeconfig=$_.kubeconfig + + kubectl config use-context default --kubeconfig=$_.kubeconfig +} +``` + Results: ``` @@ -61,6 +94,7 @@ worker-2.kubeconfig Generate a kubeconfig file for the `kube-proxy` service: +#### Linux & OS X ``` kubectl config set-cluster kubernetes-the-hard-way \ --certificate-authority=ca.pem \ @@ -88,14 +122,50 @@ kubectl config set-context default \ kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig ``` +#### Windows +``` +kubectl config set-cluster kubernetes-the-hard-way ` + --certificate-authority=ca.pem ` + --embed-certs=true ` + --server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443 ` + --kubeconfig=kube-proxy.kubeconfig +``` + +``` +kubectl config set-credentials kube-proxy ` + --client-certificate=kube-proxy.pem ` + --client-key=kube-proxy-key.pem ` + --embed-certs=true ` + --kubeconfig=kube-proxy.kubeconfig +``` + +``` +kubectl config set-context default ` + --cluster=kubernetes-the-hard-way ` + --user=kube-proxy ` + --kubeconfig=kube-proxy.kubeconfig +``` + +``` +kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig +``` + ## Distribute the Kubernetes Configuration Files Copy the appropriate `kubelet` and `kube-proxy` kubeconfig files to each worker instance: +#### Linux & OS X ``` for instance in worker-0 worker-1 worker-2; do gcloud compute scp ${instance}.kubeconfig kube-proxy.kubeconfig ${instance}:~/ done ``` +#### Windows +``` +@('worker-0','worker-1','worker-2') | ForEach-Object { + gcloud compute scp $_.kubeconfig kube-proxy.kubeconfig $_:/home/$env:USERNAME/ +} +``` + Next: [Generating the Data Encryption Config and Key](06-data-encryption-keys.md) diff --git a/docs/06-data-encryption-keys.md b/docs/06-data-encryption-keys.md index 233bce2..db2a040 100644 --- a/docs/06-data-encryption-keys.md +++ b/docs/06-data-encryption-keys.md @@ -8,14 +8,21 @@ In this lab you will generate an encryption key and an [encryption config](https Generate an encryption key: +#### Linux & OS X ``` ENCRYPTION_KEY=$(head -c 32 /dev/urandom | base64) ``` +#### Windows +``` +$ENCRYPTION_KEY=[System.Convert]::ToBase64String($(0..31 | ForEach-Object { Get-Random -Minimum 0 -Maximum 255 } )) +``` + ## The Encryption Config File Create the `encryption-config.yaml` encryption config file: +#### Linux & OS X ``` cat > encryption-config.yaml <