diff --git a/docs/assets/scripts/developer/k3d-dev.sh b/docs/assets/scripts/developer/k3d-dev.sh index 7ae8743890dc37df7da9431ae71a96f42359ed49..dedf71341d3f853e6d39c4f662d0ffaa15e718d5 100755 --- a/docs/assets/scripts/developer/k3d-dev.sh +++ b/docs/assets/scripts/developer/k3d-dev.sh @@ -1,8 +1,16 @@ #!/bin/bash #### Global variables - These allow the script to be run by non-bigbang devs easily -VPC_ID=vpc-065ffa1c7b2a2b979 -AMI_ID=ami-84556de5 +if [[ -z "${VPC_ID}" ]]; then + # default + VPC_ID=vpc-065ffa1c7b2a2b979 +fi + +if [[ -z "${AMI_ID}" ]]; then + # default + AMI_ID=ami-84556de5 +fi + #### Preflight Checks # Check that the VPC is available EXISTING_VPC=$(aws ec2 describe-vpcs | grep ${VPC_ID}) @@ -426,7 +434,7 @@ then echo echo - echo "copy kubeconfig" + echo "copying kubeconfig to workstation..." scp -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP}:/home/ubuntu/.kube/config ~/.kube/${AWSUSERNAME}-dev-config if [[ "$PRIVATE_IP" == true ]] then @@ -434,6 +442,7 @@ then else # default is to use public ip $sed_gsed -i "s/0\.0\.0\.0/${PublicIP}/g" ~/.kube/${AWSUSERNAME}-dev-config fi + echo elif [[ "$PRIVATE_IP" == true ]] then echo "using private ip for k3d" @@ -442,21 +451,21 @@ then ssh -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP} "kubectl cluster-info" echo echo - echo "copy kubeconfig" + echo "copying kubeconfig to workstation..." scp -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP}:/home/ubuntu/.kube/config ~/.kube/${AWSUSERNAME}-dev-config $sed_gsed -i "s/0\.0\.0\.0/${PrivateIP}/g" ~/.kube/${AWSUSERNAME}-dev-config - + echo else # default is public ip echo "using public ip for k3d" ssh -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP} "k3d cluster create --servers 1 --agents 3 --volume /etc/machine-id:/etc/machine-id@server:0 --volume /etc/machine-id:/etc/machine-id@agent:0,1,2 --k3s-arg "--disable=traefik@server:0" --k3s-arg "--disable=metrics-server@server:0" --k3s-arg "--tls-san=${PublicIP}@server:0" --port 80:80@loadbalancer --port 443:443@loadbalancer --api-port 6443" ssh -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP} "kubectl config use-context k3d-k3s-default" ssh -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP} "kubectl cluster-info" - echo echo - echo "copy kubeconfig" + echo "copying kubeconfig to workstation..." scp -i ~/.ssh/${KeyName}.pem -o StrictHostKeyChecking=no ubuntu@${PublicIP}:/home/ubuntu/.kube/config ~/.kube/${AWSUSERNAME}-dev-config $sed_gsed -i "s/0\.0\.0\.0/${PublicIP}/g" ~/.kube/${AWSUSERNAME}-dev-config + echo fi # add tools @@ -473,8 +482,7 @@ if [[ "$METAL_LB" == true ]]; then sudo sed -i '/bigbang.dev/d' /etc/hosts sudo bash -c "echo '## begin bigbang.dev section' >> /etc/hosts" sudo bash -c "echo 172.20.1.240 keycloak.bigbang.dev >> /etc/hosts" - sudo bash -c "echo 172.20.1.241 kiali.bigbang.dev >> /etc/hosts" - sudo bash -c "echo 172.20.1.242 gitlab.bigbang.dev >> /etc/hosts" + sudo bash -c "echo 172.20.1.241 gitlab.bigbang.dev >> /etc/hosts" sudo bash -c "echo '## end bigbang.dev section' >> /etc/hosts" ENDSSH fi @@ -489,61 +497,61 @@ echo "SAVE THE FOLLOWING INSTRUCTIONS INTO A TEMPORARY TEXT DOCUMENT SO THAT YOU echo "NOTE: The EC2 instance will automatically terminate at 08:00 UTC unless you delete the cron job" echo echo "ssh to instance:" -echo "ssh -i ~/.ssh/${KeyName}.pem ubuntu@${PublicIP}" +echo " ssh -i ~/.ssh/${KeyName}.pem ubuntu@${PublicIP}" echo - -if [[ "$METAL_LB" == true ]] +echo "To use kubectl from your local workstation you must set the KUBECONFIG environment variable:" +echo " export KUBECONFIG=~/.kube/${AWSUSERNAME}-dev-config" +if [[ "$PRIVATE_IP" == true ]] then - if [[ "$PRIVATE_IP" == true ]] - then - echo "Start sshuttle:" - echo "sshuttle --dns -vr ubuntu@${PublicIP} 172.31.0.0/16 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem -D 127.0.0.1:12345'" - else # using MetalLB and public IP - echo "OPTION 1 TO ACCESS APPLICATIONS" - echo "To access apps from browser start ssh with application-level port forwarding:" - echo "ssh -i ~/.ssh/${KeyName}.pem ubuntu@${PublicIP} -D 127.0.0.1:12345" - echo "OPTION 2 TO ACCESS APPLICATIONS" - echo "To access apps from browser and from the workstation command line start sshuttle" - echo "sshuttle --dns -vr ubuntu@${PublicIP} 172.20.1.0/24 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem'" - fi -elif [[ "$PRIVATE_IP" == true ]] -then - echo "Start sshuttle:" - echo "sshuttle --dns -vr ubuntu@${PublicIP} 172.31.0.0/16 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem'" + echo "The cluster connection will not work until you start sshuttle as described below." fi - -echo -echo "To use kubectl from your local workstation you must set the KUBECONFIG environment variable:" -echo "export KUBECONFIG=~/.kube/${AWSUSERNAME}-dev-config" echo -if [[ "$METAL_LB" == true ]] -then # using MetalLB and public IP - echo "OPTION 1 TO ACCESS APPLICATIONS" - echo "Do not edit /etc/hosts on your local workstation." - echo "To access apps from a browser edit /etc/hosts on the EC2 instance. Sample /etc/host entries have already been added there." - echo "Manually add more hostnames as needed." - echo "The IPs to use come from the istio-system services of type LOADBALANCER EXTERNAL-IP that are created when Istio is deployed." - echo "You must use Firefox browser with with manual SOCKs v5 proxy configuration to localhost with port 12345." - echo "Also ensure 'Proxy DNS when using SOCKS v5' is checked." - echo "Or, with other browsers like Chrome you could use a browser plugin like foxyproxy to do the same thing as Firefox." - echo "OPTION 2 TO ACCESS APPLICATIONS" - echo "To access apps from a browser and from workstation command line" - echo "edit your workstation /etc/hosts to add the LOADBALANCER EXTERNAL-IPs from the istio-sytem servcies with application hostnames." - echo "Here is an example. You might have to change this depending on the number of gateways you configure for k8s cluster." - echo "# METALLB" - echo "172.20.1.240 keycloak.bigbang.dev vault.bigbang.dev" - echo "172.20.1.241 kiali.bigbang.dev" - echo "172.20.1.242 sonarqube.bigbang.dev prometheus.bigbang.dev nexus.bigbang.dev gitlab.bigbang.dev" - echo -elif [[ "$PRIVATE_IP" == true ]] +if [[ "$METAL_LB" == true ]] # using MetalLB then - echo "To access apps from a browser edit your /etc/hosts to add the private IP of your instance with application hostnames. Example:" - echo "${PrivateIP} gitlab.bigbang.dev prometheus.bigbang.dev kibana.bigbang.dev" + if [[ "$PRIVATE_IP" == true ]] + then # using MetalLB and private IP + echo "Start sshuttle in a separate terminal window:" + echo " sshuttle --dns -vr ubuntu@${PublicIP} 172.31.0.0/16 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem -D 127.0.0.1:12345'" + echo "Do not edit /etc/hosts on your local workstation." + echo "Edit /etc/hosts on the EC2 instance. Sample /etc/host entries have already been added there." + echo "Manually add more hostnames as needed." + echo "The IPs to use come from the istio-system services of type LOADBALANCER EXTERNAL-IP that are created when Istio is deployed." + echo "You must use Firefox browser with with manual SOCKs v5 proxy configuration to localhost with port 12345." + echo "Also ensure 'Proxy DNS when using SOCKS v5' is checked." + echo "Or, with other browsers like Chrome you could use a browser plugin like foxyproxy to do the same thing as Firefox." + else # using MetalLB and public IP + echo "OPTION 1: ACCESS APPLICATIONS WITH WEB BROWSER ONLY" + echo "To access apps from browser only start ssh with application-level port forwarding:" + echo " ssh -i ~/.ssh/${KeyName}.pem ubuntu@${PublicIP} -D 127.0.0.1:12345" + echo "Do not edit /etc/hosts on your local workstation." + echo "Edit /etc/hosts on the EC2 instance. Sample /etc/host entries have already been added there." + echo "Manually add more hostnames as needed." + echo "The IPs to use come from the istio-system services of type LOADBALANCER EXTERNAL-IP that are created when Istio is deployed." + echo "You must use Firefox browser with with manual SOCKs v5 proxy configuration to localhost with port 12345." + echo "Also ensure 'Proxy DNS when using SOCKS v5' is checked." + echo "Or, with other browsers like Chrome you could use a browser plugin like foxyproxy to do the same thing as Firefox." + echo + echo "OPTION 2: ACCESS APPLICATIONS WITH WEB BROWSER AND COMMAND LINE" + echo "To access apps from browser and from the workstation command line start sshuttle in a separate terminal window." + echo " sshuttle --dns -vr ubuntu@${PublicIP} 172.20.1.0/24 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem'" + echo "Edit your workstation /etc/hosts to add the LOADBALANCER EXTERNAL-IPs from the istio-sytem servcies with application hostnames." + echo "Here is an example. You might have to change this depending on the number of gateways you configure for k8s cluster." + echo " # METALLB ISTIO INGRESS IPs" + echo " 172.20.1.240 keycloak.bigbang.dev vault.bigbang.dev" + echo " 172.20.1.241 sonarqube.bigbang.dev prometheus.bigbang.dev nexus.bigbang.dev gitlab.bigbang.dev" + fi +elif [[ "$PRIVATE_IP" == true ]] # not using MetalLB +then # Not using MetalLB and using private IP + echo "Start sshuttle in a separate terminal window:" + echo " sshuttle --dns -vr ubuntu@${PublicIP} 172.31.0.0/16 --ssh-cmd 'ssh -i ~/.ssh/${KeyName}.pem'" echo -else # default is to use the public ip - echo "To access apps from a browser edit your /etc/hosts to add the public IP of your instance with application hostnames." + echo "To access apps from a browser edit your /etc/hosts to add the private IP of your EC2 instance with application hostnames. Example:" + echo " ${PrivateIP} gitlab.bigbang.dev prometheus.bigbang.dev kibana.bigbang.dev" + echo +else # Not using MetalLB and using pubilc IP. This is the default + echo "To access apps from a browser edit your /etc/hosts to add the public IP of your EC2 instance with application hostnames." echo "Example:" - echo "${PublicIP} gitlab.bigbang.dev prometheus.bigbang.dev kibana.bigbang.dev" + echo " ${PublicIP} gitlab.bigbang.dev prometheus.bigbang.dev kibana.bigbang.dev" echo fi diff --git a/docs/developer/aws-k3d-script.md b/docs/developer/aws-k3d-script.md index 3f819f48043385ecf5a8f7a183a5b225eb86c125..fc9594563fb64238fd28ec7d0fb0932d053fb406 100644 --- a/docs/developer/aws-k3d-script.md +++ b/docs/developer/aws-k3d-script.md @@ -54,6 +54,22 @@ k3d-dev.sh -b -p -m -d -h -d destroy related AWS resources -h output help ``` +## To use a different AWS profile, VPC, or AMI +The script uses the default AWS profile and defaults the VPC id and AMI id. +To change this default behavior you can export environment variables before running the script. + +Run the script with a specifc AWS profile by first exporting the AWS_PROFILE environment variable +``` +export AWS_PROFILE=my-aws-profile +``` +To run the script with a specific VPC +``` +export VPC_ID=vpc-XXXXXXXXXXXX +``` +To run the script with a specific AMI +``` +export AMI_ID=ami-XXXXXXXXXX +``` ## After Running The Script