Created
November 12, 2021 04:05
-
-
Save Vertiwell/5384a24ae660ef386108b13df50033f0 to your computer and use it in GitHub Desktop.
hashicorp_consul-ext-access.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Consul Dashboard | |
## Create SSL access to the Consul dashboard | |
## Set Variables: | |
# Get the Cert-Manager Issuer | |
ISSUER=$(kubectl get clusterissuer -o json | jq -r ".items[].metadata.name") | |
# Set a domain to use (needs to be real if you want to access this externally from the internet) | |
echo "Provide a domain to use (i.e: example.com):" | |
read DOMAIN | |
# Name of the application | |
APP=consul | |
# Namespace the application is in | |
NAMESPACE=consul | |
# Service we need to target to direct traffic to | |
SERVICE=consul-consul-ui | |
# The port the service uses | |
PORT=80 | |
# Create the Certificate (standard template against name.whatever.com your domain is) | |
printf "apiVersion: cert-manager.io/v1\nkind: Certificate\nmetadata:\n name: "$APP"-dashboard-cert\n namespace: "$NAMESPACE"\nspec:\n commonName: "$APP"."$DOMAIN"\n secretName: "$APP"-dashboard-cert\n dnsNames:\n - "$APP"."$DOMAIN"\n issuerRef:\n name: "$ISSUER"\n kind: ClusterIssuer" > $APP-dashboard-cert.yaml && kubectl apply -f $APP-dashboard-cert.yaml && \ | |
# Create the IngressRoute to direct traffic to your application | |
printf "apiVersion: traefik.containo.us/v1alpha1\nkind: IngressRoute\nmetadata:\n name: "$APP"-dashboard-ingress\n namespace: "$NAMESPACE"\nspec:\n entryPoints:\n - websecure\n routes:\n - match: Host(\`"$APP"."$DOMAIN"\`) && PathPrefix(\`/\`)\n kind: Rule\n services:\n - name: "$SERVICE"\n port: "$PORT"\n tls:\n secretName: "$APP"-dashboard-cert" > $APP-dashboard-ingress.yaml && kubectl apply -f $APP-dashboard-ingress.yaml && \ | |
# Cleanup | |
rm $APP-dashboard* && \ | |
# Provide the user the URL | |
echo "URL is https://consul.$DOMAIN.com/ui/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment