Skip to content

Instantly share code, notes, and snippets.

@howardjohn
Last active November 5, 2020 21:20
Show Gist options
  • Save howardjohn/458f4f9416a3fa1a014feb168e9922ea to your computer and use it in GitHub Desktop.
Save howardjohn/458f4f9416a3fa1a014feb168e9922ea to your computer and use it in GitHub Desktop.
Local Istio Development
# Build just the minimal dependencies we need
# Note: multiple builds are fast, so its fine to call this every time we run. Do not use `go run` - no caching.
alias build-local='go build -o ./out/linux_amd64/release ./pilot/cmd/pilot-agent ./pilot/cmd/pilot-discovery'
# Run pilot. Will use your local kubeconfig, or override with --kubeconfig flag
alias pilot-local='build-local && ./out/linux_amd64/release/pilot-discovery discovery'
# Fetch bootstrap token and root cert
function proxy-local-bootstrap() {
mkdir -p ./var/run/secrets/tokens ./var/run/secrets/istio
echo '{"kind":"TokenRequest","apiVersion":"authentication.k8s.io/v1","spec":{"audiences":["istio-ca"], "expirationSeconds":2592000}}' | kubectl create --raw /api/v1/namespaces/default/serviceaccounts/default/token -f - | jq -j '.status.token' > ./var/run/secrets/tokens/istio-token
kubectl -n istio-system get secret istio-ca-secret -ojsonpath='{.data.ca-cert\.pem}' | base64 -d > ./var/run/secrets/istio/root-cert.pem
}
# Run proxy. Replace ~/kube/local/proxyconfig.yaml with path to your proxyconfig.
alias proxy-local='build-local && PROXY_CONFIG="$(cat ~/kube/local/proxyconfig.yaml | envsubst)" ./out/linux_amd64/release/pilot-agent proxy sidecar'
alias gateway-local='build-local && ISTIO_META_CLUSTER_ID=Kubernetes ISTIO_METAJSON_LABELS="{\"istio\": \"ingressgateway\", \"app\": \"istio-ingressgateway\"}" PROXY_CONFIG="$(cat ~/kube/local/proxyconfig.yaml | envsubst)" ./out/linux_amd64/release/pilot-agent proxy router'
# My proxyconfig:
# binaryPath: $GOPATH/src/istio.io/istio/out/linux_amd64/release/envoy
# configPath: $HOME/kube/local/proxy
# proxyBootstrapTemplatePath: $GOPATH/src/istio.io/istio/tools/packaging/common/envoy_bootstrap.json
# discoveryAddress: localhost:15012
# statusPort: 15020
# terminationDrainDuration: 0s
# Example running in docker
docker run --network host \
-v "${PWD}/var:/var" \
-v "${PWD}/tools/packaging/common/envoy_bootstrap.json":"${PWD}/tools/packaging/common/envoy_bootstrap.json" \
-v "${PWD}/out/linux_amd64/envoy":"${PWD}/out/linux_amd64/envoy" \
-e PROXY_CONFIG="$(cat ~/kube/local/proxyconfig.yaml | envsubst)" istio/proxyv2 proxy sidecar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment