Replace `jq` with `--query` param in AWS commands.

pull/55/head
Stephen Price 2016-09-12 12:10:44 -07:00
parent e2587a74c7
commit 98cba351a0
7 changed files with 106 additions and 71 deletions

View File

@ -51,7 +51,7 @@ AWS
This tutorial assumes you have access to one of the following:
* [Google Cloud Platform](https://cloud.google.com) and the [Google Cloud SDK](https://cloud.google.com/sdk/) (125.0.0+)
* [Amazon Web Services](https://aws.amazon.com), the [AWS CLI](https://aws.amazon.com/cli) (1.10.63+), and [jq](https://stedolan.github.io/jq) (1.5+)
* [Amazon Web Services](https://aws.amazon.com) and the [AWS CLI](https://aws.amazon.com/cli) (1.10.63+)
While GCP or AWS will be used for basic infrastructure needs, the things learned in this tutorial apply to every platform.

View File

@ -18,8 +18,9 @@ To make our Kubernetes control plane remotely accessible, a public IP address wi
```
VPC_ID=$(aws ec2 create-vpc \
--cidr-block 10.240.0.0/16 | \
jq -r '.Vpc.VpcId')
--cidr-block 10.240.0.0/16 \
--output text \
--query '.Vpc.VpcId')
```
```
@ -45,8 +46,9 @@ aws ec2 modify-vpc-attribute \
```
DHCP_OPTION_SET_ID=$(aws ec2 create-dhcp-options \
--dhcp-configuration "Key=domain-name,Values=us-west-2.compute.internal" \
"Key=domain-name-servers,Values=AmazonProvidedDNS" | \
jq -r '.DhcpOptions.DhcpOptionsId')
"Key=domain-name-servers,Values=AmazonProvidedDNS" \
--output text \
--query 'DhcpOptions.DhcpOptionsId')
```
```
@ -68,8 +70,9 @@ Create a subnet for the Kubernetes cluster:
```
SUBNET_ID=$(aws ec2 create-subnet \
--vpc-id ${VPC_ID} \
--cidr-block 10.240.0.0/24 | \
jq -r '.Subnet.SubnetId')
--cidr-block 10.240.0.0/24 \
--output text \
--query 'Subnet.SubnetId')
```
```
@ -81,8 +84,9 @@ aws ec2 create-tags \
### Internet Gateways
```
INTERNET_GATEWAY_ID=$(aws ec2 create-internet-gateway | \
jq -r '.InternetGateway.InternetGatewayId')
INTERNET_GATEWAY_ID=$(aws ec2 create-internet-gateway \
--output text \
--query 'InternetGateway.InternetGatewayId')
```
```
@ -101,8 +105,9 @@ aws ec2 attach-internet-gateway \
```
ROUTE_TABLE_ID=$(aws ec2 create-route-table \
--vpc-id ${VPC_ID} | \
jq -r '.RouteTable.RouteTableId')
--vpc-id ${VPC_ID} \
--output text \
--query 'RouteTable.RouteTableId')
```
```
@ -130,8 +135,9 @@ aws ec2 create-route \
SECURITY_GROUP_ID=$(aws ec2 create-security-group \
--group-name kubernetes \
--description "Kubernetes security group" \
--vpc-id ${VPC_ID} | \
jq -r '.GroupId')
--vpc-id ${VPC_ID} \
--output text \
--query 'GroupId')
```
```
@ -250,8 +256,9 @@ IMAGE_ID="ami-746aba14"
### Generate A SSH Key Pair
```
aws ec2 create-key-pair --key-name kubernetes | \
jq -r '.KeyMaterial' > ~/.ssh/kubernetes_the_hard_way
aws ec2 create-key-pair --key-name kubernetes \
--output text \
--query 'KeyMaterial' > ~/.ssh/kubernetes_the_hard_way
```
```
@ -268,8 +275,9 @@ Once the virtual machines are created you'll be able to login into each machine
```
WORKER_0_PUBLIC_IP_ADDRESS=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=worker0" | \
jq -j '.Reservations[].Instances[].PublicIpAddress')
--filters "Name=tag:Name,Values=worker0" \
--output text \
--query 'Reservations[].Instances[].PublicIpAddress')
```
> The instance public IP address can also be obtained from the EC2 console. Each node will be tagged with a unique name.
@ -291,8 +299,9 @@ ETCD_0_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.10 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -310,8 +319,9 @@ ETCD_1_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.11 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -329,8 +339,9 @@ ETCD_2_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.12 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -351,8 +362,9 @@ CONTROLLER_0_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.20 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query '.Instances[].InstanceId')
```
```
@ -377,8 +389,9 @@ CONTROLLER_1_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.21 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -403,8 +416,9 @@ CONTROLLER_2_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.22 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -431,8 +445,9 @@ WORKER_0_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.30 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -457,8 +472,9 @@ WORKER_1_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.31 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -483,8 +499,9 @@ WORKER_2_INSTANCE_ID=$(aws ec2 run-instances \
--security-group-ids ${SECURITY_GROUP_ID} \
--instance-type t2.small \
--private-ip-address 10.240.0.32 \
--subnet-id ${SUBNET_ID} | \
jq -r '.Instances[].InstanceId')
--subnet-id ${SUBNET_ID} \
--output text \
--query 'Instances[].InstanceId')
```
```
@ -504,8 +521,9 @@ aws ec2 create-tags \
```
aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" | \
jq -j '.Reservations[].Instances[] | .InstanceId, " ", .Placement.AvailabilityZone, " ", .PrivateIpAddress, " ", .PublicIpAddress, "\n"'
--filters "Name=instance-state-name,Values=running" \
--output text \
--query 'Reservations[].Instances[].{ID:InstanceId, AZ:Placement.AvailabilityZone, PrivateIP:PrivateIpAddress, PublicIP:PublicIpAddress}'
```
```
i-f3714f2e us-west-2c 10.240.0.22 XX.XXX.XX.XX

View File

@ -133,8 +133,9 @@ KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes \
```
KUBERNETES_PUBLIC_ADDRESS=$(aws elb describe-load-balancers \
--load-balancer-name kubernetes | \
jq -r '.LoadBalancerDescriptions[].DNSName')
--load-balancer-name kubernetes \
--output text \
--query '.LoadBalancerDescriptions[].DNSName')
```
---
@ -236,8 +237,9 @@ The following command will:
```
for host in ${KUBERNETES_HOSTS[*]}; do
PUBLIC_IP_ADDRESS=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=${host}" | \
jq -j '.Reservations[].Instances[].PublicIpAddress')
--filters "Name=tag:Name,Values=${host}" \
--output text \
--query 'Reservations[].Instances[].PublicIpAddress')
scp ca.pem kubernetes-key.pem kubernetes.pem \
ubuntu@${PUBLIC_IP_ADDRESS}:~/
done

View File

@ -33,8 +33,9 @@ KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes \
```
KUBERNETES_PUBLIC_ADDRESS=$(aws elb describe-load-balancers \
--load-balancer-name kubernetes | \
jq -r '.LoadBalancerDescriptions[].DNSName')
--load-balancer-name kubernetes \
--output text \
--query 'LoadBalancerDescriptions[].DNSName')
```
---

View File

@ -76,14 +76,16 @@ gcloud compute routes create kubernetes-route-10-200-2-0-24 \
```
ROUTE_TABLE_ID=$(aws ec2 describe-route-tables \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.RouteTables[].RouteTableId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'RouteTables[].RouteTableId')
```
```
WORKER_0_INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=worker0" | \
jq -j '.Reservations[].Instances[].InstanceId')
--filters "Name=tag:Name,Values=worker0" \
--output text \
--query 'Reservations[].Instances[].InstanceId')
```
```
@ -95,8 +97,9 @@ aws ec2 create-route \
```
WORKER_1_INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=worker1" | \
jq -j '.Reservations[].Instances[].InstanceId')
--filters "Name=tag:Name,Values=worker1" \
--output text \
--query 'Reservations[].Instances[].InstanceId')
```
```
@ -108,8 +111,9 @@ aws ec2 create-route \
```
WORKER_2_INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=worker2" | \
jq -j '.Reservations[].Instances[].InstanceId')
--filters "Name=tag:Name,Values=worker2" \
--output text \
--query 'Reservations[].Instances[].InstanceId')
```
```

View File

@ -59,8 +59,9 @@ NODE_PUBLIC_IP=$(gcloud compute instances describe worker0 \
```
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.SecurityGroups[].GroupId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'SecurityGroups[].GroupId')
```
```
@ -75,8 +76,9 @@ Grab the `EXTERNAL_IP` for one of the worker nodes:
```
NODE_PUBLIC_IP=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=worker0" | \
jq -j '.Reservations[].Instances[].PublicIpAddress')
--filters "Name=tag:Name,Values=worker0" \
--output text \
--query 'Reservations[].Instances[].PublicIpAddress')
```
---

View File

@ -68,8 +68,9 @@ KUBERNETES_HOSTS=(controller0 controller1 controller2 etcd0 etcd1 etcd2 worker0
```
for host in ${KUBERNETES_HOSTS[*]}; do
INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=${host}" | \
jq -j '.Reservations[].Instances[].InstanceId')
--filters "Name=tag:Name,Values=${host}" \
--output text \
--query 'Reservations[].Instances[].InstanceId')
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
done
```
@ -124,14 +125,16 @@ aws elb delete-load-balancer \
```
VPC_ID=$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Vpcs[].VpcId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'Vpcs[].VpcId')
```
```
INTERNET_GATEWAY_ID=$(aws ec2 describe-internet-gateways \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.InternetGateways[].InternetGatewayId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'InternetGateways[].InternetGatewayId')
```
```
@ -149,8 +152,9 @@ aws ec2 delete-internet-gateway \
```
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.SecurityGroups[].GroupId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'SecurityGroups[].GroupId')
```
```
@ -162,8 +166,9 @@ aws ec2 delete-security-group \
```
SUBNET_ID=$(aws ec2 describe-subnets \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Subnets[].SubnetId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'Subnets[].SubnetId')
```
```
@ -174,8 +179,9 @@ aws ec2 delete-subnet --subnet-id ${SUBNET_ID}
```
ROUTE_TABLE_ID=$(aws ec2 describe-route-tables \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.RouteTables[].RouteTableId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'RouteTables[].RouteTableId')
```
```
@ -186,8 +192,9 @@ aws ec2 delete-route-table --route-table-id ${ROUTE_TABLE_ID}
```
VPC_ID=$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.Vpcs[].VpcId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'Vpcs[].VpcId')
```
```
@ -198,8 +205,9 @@ aws ec2 delete-vpc --vpc-id ${VPC_ID}
```
DHCP_OPTION_SET_ID=$(aws ec2 describe-dhcp-options \
--filters "Name=tag:Name,Values=kubernetes" | \
jq -r '.DhcpOptions[].DhcpOptionsId')
--filters "Name=tag:Name,Values=kubernetes" \
--output text \
--query 'DhcpOptions[].DhcpOptionsId')
```
```