Skip to content

Instantly share code, notes, and snippets.

@ymkjp
Last active December 30, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymkjp/8604612eca2c11d6bd99f7233134bcf3 to your computer and use it in GitHub Desktop.
Save ymkjp/8604612eca2c11d6bd99f7233134bcf3 to your computer and use it in GitHub Desktop.
Script to install Knative to Minikube without Istio's sidecar injection
#!/usr/bin/env bash
# https://knative.dev/docs/install/knative-with-minikube/
# https://knative.dev/docs/install/installing-istio/#installing-istio-without-sidecar-injection
set -ue
init-local-knaive () {
download-istio
init-istio-lean
init-gateway
init-knative
get-istio-system-pods
get-knative-pods
print-local-gateway
}
find-istio-path () {
find . -type d -name 'istio-*' | head -n 1
}
download-istio () {
ISTIO_PATH="$(find-istio-path)"
if [[ -z "${ISTIO_PATH}" ]]; then
curl -L https://git.io/getLatestIstio | sh -
fi
}
init-istio-lean () {
# Install Istio without sidecar injection
ISTIO_PATH="$(find-istio-path)"
for i in "${ISTIO_PATH}/"install/kubernetes/helm/istio-init/files/crd*yaml; do
kubectl apply -f $i;
done
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: istio-system
labels:
istio-injection: disabled
EOF
# A lighter template, with just pilot/gateway.
# Based on install/kubernetes/helm/istio/values-istio-minimal.yaml
helm template --namespace=istio-system \
--set prometheus.enabled=false \
--set mixer.enabled=false \
--set mixer.policy.enabled=false \
--set mixer.telemetry.enabled=false \
`# Pilot doesn't need a sidecar.` \
--set pilot.sidecar=false \
--set pilot.resources.requests.memory=128Mi \
`# Disable galley (and things requiring galley).` \
--set galley.enabled=false \
--set global.useMCP=false \
`# Disable security / policy.` \
--set security.enabled=false \
--set global.disablePolicyChecks=true \
`# Disable sidecar injection.` \
--set sidecarInjectorWebhook.enabled=false \
--set global.proxy.autoInject=disabled \
--set global.omitSidecarInjectorConfigMap=true \
--set gateways.istio-ingressgateway.autoscaleMin=1 \
--set gateways.istio-ingressgateway.autoscaleMax=2 \
`# Set pilot trace sampling to 100%` \
--set pilot.traceSampling=100 \
"${ISTIO_PATH}/"install/kubernetes/helm/istio \
> ./istio-lean.yaml
kubectl apply -f istio-lean.yaml
}
init-gateway () {
# Installing cluster-local-gateway
ISTIO_PATH="$(find-istio-path)"
helm template --namespace=istio-system \
--set gateways.custom-gateway.autoscaleMin=1 \
--set gateways.custom-gateway.autoscaleMax=2 \
--set gateways.custom-gateway.cpu.targetAverageUtilization=60 \
--set gateways.custom-gateway.labels.app='cluster-local-gateway' \
--set gateways.custom-gateway.labels.istio='cluster-local-gateway' \
--set gateways.custom-gateway.type='ClusterIP' \
--set gateways.istio-ingressgateway.enabled=false \
--set gateways.istio-egressgateway.enabled=false \
--set gateways.istio-ilbgateway.enabled=false \
"${ISTIO_PATH}/"install/kubernetes/helm/istio \
-f "${ISTIO_PATH}/"install/kubernetes/helm/istio/example-values/values-istio-gateways.yaml \
| sed -e "s/custom-gateway/cluster-local-gateway/g" -e "s/customgateway/clusterlocalgateway/g" \
> ./istio-local-gateway.yaml
kubectl apply -f istio-local-gateway.yaml
}
init-knative () {
# Installing Knative
kubectl apply --selector knative.dev/crd-install=true \
--filename https://github.com/knative/serving/releases/download/v0.11.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.11.0/release.yaml \
--filename https://github.com/knative/serving/releases/download/v0.11.0/monitoring.yaml
kubectl apply --filename https://github.com/knative/serving/releases/download/v0.11.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.11.0/release.yaml \
--filename https://github.com/knative/serving/releases/download/v0.11.0/monitoring.yaml
}
get-istio-system-pods () {
# Verify your Istio installation
kubectl get pods --namespace istio-system -o name
}
get-knative-pods () {
# Verify your Knative installation
kubectl get pods --namespace knative-serving -o name
kubectl get pods --namespace knative-eventing -o name
kubectl get pods --namespace knative-monitoring -o name
}
print-local-gateway () {
INGRESSGATEWAY=istio-ingressgateway
echo -e "Local gateway:\t" $(minikube ip):$(kubectl get svc $INGRESSGATEWAY --namespace istio-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
}
init-local-knaive
minikube start --memory=16384 --cpus="$(nproc)" --disk-size=30g \
--extra-config=apiserver.enable-admission-plugins="LimitRanger,NamespaceExists,NamespaceLifecycle,ResourceQuota,ServiceAccount,DefaultStorageClass,MutatingAdmissionWebhook"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment