#!/usr/bin/env bash set -e set -o noglob # Usage: # curl https://get.ambientmesh.io | ENV_VAR=... sh - # or # wget -qO- https://get.ambientmesh.io | ENV_VAR=... sh - # # Environment Variables # DISTRO: The Kubernetes distribution. Supported values are: gke, k3s, k3d, minikube, microk8s, openshift, and default. # k3d, minikube, microk8s, and openshift are currently not able to be automatically detected but can be manually specified. # CONTEXT: The Kubernetes context to use. Default is the current context. # # Purpose: # The purpose of this script is to automatically detect the Kubernetes distribution to apply the correct manifest to the cluster # as well as apply the Gateway API CRDs. function k() { kubectl --context "$CONTEXT" $@ } function main() { if ! command -v kubectl > /dev/null; then echo "kubectl is not installed. Please install kubectl." exit 1 fi GATEWAY_API_MANIFEST_URL="https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml" AMBIENTMESH_HOST=${AMBIENTMESH_HOST:-"get.ambientmesh.io"} BASE_URL="https://${AMBIENTMESH_HOST}" # Allow overriding context without changing the current context. CONTEXT=${CONTEXT:-$(kubectl config current-context)} echo "* Determining Kubernetes cluster distribution..." cluster_version="" if command -v jq > /dev/null; then cluster_version=$(k version -o json | jq -r '.serverVersion.gitVersion') else cluster_version=$(k version -o json | grep -A 5 '"serverVersion"' | grep '"gitVersion"' | sed 's/.*"gitVersion": "\(.*\)",/\1/' | tr -d '\n') fi echo " * Detected Kubernetes cluster version $cluster_version." echo "" distro=${DISTRO:-""} if [[ -z "$distro" ]]; then echo "* Determining if your Kubernetes distribution requires custom settings..." case "$cluster_version" in *gke*) echo " * Using settings for Google Kubernetes Engine (GKE)." distro="gke" ;; *k3s*) echo " * Using settings for k3s." distro="k3s" ;; *) echo " * Using default settings." distro=default ;; esac else # Check if DISTRO is set to a valid value. Accepted values are: gke, k3s, minikube, microk8s, openshift, and default. # If not, exit with an error. case "$distro" in gke|k3s|k3d|minikube|microk8s|openshift|default) ;; *) echo "* Invalid value for DISTRO: $distro" exit 1 ;; esac fi echo "" echo "* Installing Istio & Gateway API..." echo "" k create namespace istio-system || true k apply -f "$BASE_URL/yamls/$distro.yaml" k apply -f "$GATEWAY_API_MANIFEST_URL" echo "" echo "* Installation complete. Waiting for all components to be ready..." echo "" k rollout status deployment/istiod -n istio-system k rollout status daemonset/istio-cni-node -n istio-system k rollout status daemonset/ztunnel -n istio-system echo "" echo "* Ambient mesh is now installed and ready!" echo "" k get pods -n istio-system } main