Skip to content

Instantly share code, notes, and snippets.

@gswallow
Last active August 28, 2019 01:36
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 gswallow/fa08542f47391859b0d621057ed95fde to your computer and use it in GitHub Desktop.
Save gswallow/fa08542f47391859b0d621057ed95fde to your computer and use it in GitHub Desktop.
Indy DevOps Meetup 8/2019 - Istio

Install istio

Mac friendly. Probably not Linux friendly. Throughout the course of these commands, feel free to check out the contents of the yaml files you apply with kubectl.

Get eksctl

brew tap weaveworks/tap
brew install weaveworks/tap/eksctl

Spin up a kubernetes cluster

eksctl create cluster -n indy-devops-demo -t t3.medium -N 4 -m 4 -M 4 --external-dns-access

Download istio

curl -sSL https://git.io/getLatestIstio | ISTIO_VERSION=1.2.5 sh -

Install istioctl (OS X)

brew install istioctl
# Setup shell completion (see https://istio.io/docs/ops/setup/istioctl/)

Check that your cluster supports istio

./istio-1.2.5/bin/istioctl verify-install

Install helm (OS X) (note: see https://helm.sh/docs/using_helm/#securing-your-helm-installation)

brew install kubernetes-helm

Create a service account for tiller

kubectl apply -f istio-1.2.5/install/kubernetes/helm/helm-service-account.yaml

Install tiller (note: see https://helm.sh/docs/using_helm/#securing-your-helm-installation)

helm init --service-account tiller

Add the Istio helm repo

helm repo add istio.io https://storage.googleapis.com/istio-release/releases/1.2.5/charts/

Create an istio-system namespace

kubectl create namespace istio-system

Initialize Istio CRDs

helm install istio-1.2.5/install/kubernetes/helm/istio-init \
 --name istio-init \
 --namespace istio-system \
 --set certmanager.enabled=true 

kubectl get crds | grep 'istio.io\|certmanager.k8s.io' | wc -l # 28
kubectl get crds

Install Istio

Note: there are a ton of options at https://istio.io/docs/reference/config/installation-options/#gateways-options

helm install istio-1.2.5/install/kubernetes/helm/istio \
 --name istio \
 --namespace istio-system \
 --values istio-1.2.5/install/kubernetes/helm/istio/values-istio-sds-auth.yaml \
 --set certmanager.enabled=true \
 --set certmanager.email=gswallow@gmail.com \
 --set gateways.istio-ingressgateway.sds.enabled=true \
 --set global.proxy.logLevel=info \
 --set global.sds.enabled=true \
 --set grafana.enabled=true \
 --set istiocoredns.enabled=true \
 --set kiali.enabled=true \
 --set mixer.policy.enabled=true \
 --set nodeagent.enabled=true \
 --set tracing.enabled=true

Note that we have new API resources

kubectl api-resources --api-group=networking.istio.io
kubectl api-resources --api-group=certmanager.k8s.io

Enable automatic sidecar injection for the "default" namespace

kubectl label namespace default istio-injection=enabled

Start routing traffic

From here we'll be following the Istio-supplied demo app: https://istio.io/docs/examples/bookinfo/ Deploy Istio's sample application and see that it's up and running

kubectl apply -f istio-1.2.5/samples/bookinfo/platform/kube/bookinfo.yaml
# sleep 90
kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
kubectl apply -f istio-1.2.5/samples/bookinfo/networking/bookinfo-gateway.yaml
kubectl get gw bookinfo-gateway -oyaml
kubectl get vs bookinfo -oyaml
export INGRESS_HOST=$(kubectl get service istio-ingressgateway -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
curl -s http://$INGRESS_HOST/productpage | grep -o '<title>.*</title>'

That provides us with the simplest router ever: map all HTTP requests in the world to the bookinfo app. What's going on is that you have a virtual service bound to a gateway. These items are linked together and applied to the istio-proxy container, running in the istio-ingressgateway pod that runs in the istio-ingressgateway service. Let's trace it:

kubectl get pod -l app=istio-ingressgateway -n istio-system -ojsonpath='{.items[].spec.containers[\*].name}'
kubectl get svc istio-ingressgateway -n istio-system -ojsonpath='{.metadata.labels}'
kubectl get gw bookinfo-gateway -ojsonpath='{.spec.selector}'
kubectl get vs bookinfo -ojsonpath='{.spec.gateways}'

Now, let's break it:

kubectl apply -f istio-1.2.5/samples/bookinfo/networking/destination-rule-all-mtls.yaml
kubectl get vs bookinfo -ojsonpath='{.spec.http[0].route[].destination.host}'
kubectl get dr productpage -oyaml
kubectl get service bookinfo -oyaml

(As an aside, we enabled mTLS between all services in the cluster when we installed Istio, and it just works. Mind. Blown.) Create additional virtual services:

kubectl get vs
kubectl apply -f istio-1.2.5/samples/bookinfo/networking/virtual-service-all-v1.yaml
kubectl get vs
kubectl get vs productpage -oyaml
curl -s http://$INGRESS_HOST/productpage | grep -o '<title>.*</title>'

From here, you can explore more advanced Istio features by going through their task-based tutorials: https://istio.io/docs/tasks/

apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
labels:
app: certmanager
chart: certmanager
heritage: Tiller
release: istio
name: letsencrypt-dns
spec:
acme:
email: change@me.org
dns01:
providers:
- name: route53
route53:
region: us-east-1
privateKeySecretRef:
key: ""
name: letsencrypt-dns
server: https://acme-v02.api.letsencrypt.org/directory
apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
labels:
app: certmanager
chart: certmanager
heritage: Tiller
release: istio
name: letsencrypt-staging-dns
spec:
acme:
email: change@me.org
dns01:
providers:
- name: route53
route53:
region: us-east-1
privateKeySecretRef:
key: ""
name: letsencrypt-staging-dns
server: https://acme-staging-v02.api.letsencrypt.org/directory
# The IAM policy that eksctl creates is wrong.
# {
# "Version": "2012-10-17",
# "Statement": [
# {
# "Action": [
# "route53:ListHostedZones",
# "route53:ListHostedZonesByName",
# "route53:ListResourceRecordSets",
# "route53:GetChange"
# ],
# "Resource": "*",
# "Effect": "Allow"
# }
# ]
# }
---
apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
name: bookinfo.gregonaws.net
namespace: istio-system
spec:
commonName: bookinfo.gregonaws.net
acme:
config:
- dns01:
provider: route53
domains:
- bookinfo.gregonaws.net
domains:
- bookinfo.gregonaws.net
dnsNames:
- bookinfo.gregonaws.net
issuerRef:
kind: ClusterIssuer
name: letsencrypt-staging-dns
secretName: bookinfo.gregonaws.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment