Setup a Kubernetes Cluster

    In this module, you set up a Kubernetes cluster that has Istio installed and a namespace to use throughout the tutorial.

    If you are in a workshop and the instructors provide a cluster for you, proceed to setting up your local computer.

    1. Ensure you have access to a . You can use the Google Kubernetes Engine or the .

    2. Create an environment variable to store the name of a namespace that you will use when you run the tutorial commands. You can use any name, for example .

    3. Create the namespace:

      1. $ kubectl create namespace $NAMESPACE

      If you are an instructor, you should allocate a separate namespace per each participant. The tutorial supports work in multiple namespaces simultaneously by multiple participants.

    4. Install Istio using the demo profile.

    5. Create a Kubernetes Ingress resource for these common Istio services using the kubectl command shown. It is not necessary to be familiar with each of these services at this point in the tutorial.

      The kubectl command can accept an in-line configuration to create the Ingress resources for each service:

      1. $ kubectl apply -f - <<EOF
      2. apiVersion: extensions/v1beta1
      3. kind: Ingress
      4. metadata:
      5. name: istio-system
      6. namespace: istio-system
      7. spec:
      8. rules:
      9. - host: my-istio-dashboard.io
      10. http:
      11. paths:
      12. - path: /*
      13. backend:
      14. serviceName: grafana
      15. servicePort: 3000
      16. - host: my-istio-tracing.io
      17. http:
      18. paths:
      19. - path: /*
      20. backend:
      21. serviceName: tracing
      22. servicePort: 9411
      23. - host: my-istio-logs-database.io
      24. paths:
      25. - path: /*
      26. backend:
      27. serviceName: prometheus
      28. servicePort: 9090
      29. http:
      30. paths:
      31. - path: /*
      32. backend:
      33. serviceName: kiali
      34. servicePort: 20001
      35. EOF
    6. Create a role to provide read access to the istio-system namespace. This role is required to limit permissions of the participants in the steps below.

    7. Create a service account for each participant:

      1. $ kubectl apply -f - <<EOF
      2. apiVersion: v1
      3. kind: ServiceAccount
      4. metadata:
      5. name: ${NAMESPACE}-user
      6. namespace: $NAMESPACE
      7. EOF
    8. Limit each participant’s permissions. During the tutorial, participants only need to create resources in their namespace and to read resources from istio-system namespace. It is a good practice, even if using your own cluster, to avoid interfering with other namespaces in your cluster.

      Create a role to allow read-write access to each participant’s namespace. Bind the participant’s service account to this role and to the role for reading resources from istio-system:

      1. $ kubectl apply -f - <<EOF
      2. kind: Role
      3. apiVersion: rbac.authorization.k8s.io/v1beta1
      4. metadata:
      5. name: ${NAMESPACE}-access
      6. namespace: $NAMESPACE
      7. rules:
      8. - apiGroups: ["", "extensions", "apps", "networking.k8s.io", "networking.istio.io", "authentication.istio.io",
      9. "rbac.istio.io", "config.istio.io"]
      10. resources: ["*"]
      11. verbs: ["*"]
      12. kind: RoleBinding
      13. apiVersion: rbac.authorization.k8s.io/v1beta1
      14. metadata:
      15. name: ${NAMESPACE}-access
      16. subjects:
      17. - kind: ServiceAccount
      18. name: ${NAMESPACE}-user
      19. namespace: $NAMESPACE
      20. roleRef:
      21. apiGroup: rbac.authorization.k8s.io
      22. kind: Role
      23. name: ${NAMESPACE}-access
      24. ---
      25. kind: RoleBinding
      26. apiVersion: rbac.authorization.k8s.io/v1beta1
      27. metadata:
      28. name: ${NAMESPACE}-istio-system-access
      29. namespace: istio-system
      30. subjects:
      31. - kind: ServiceAccount
      32. name: ${NAMESPACE}-user
      33. namespace: $NAMESPACE
      34. roleRef:
      35. apiGroup: rbac.authorization.k8s.io
      36. kind: Role
      37. name: istio-system-access
      38. EOF
    9. Each participant needs to use their own Kubernetes configuration file. This configuration file specifies the cluster details, the service account, the credentials and the namespace of the participant. The kubectl command uses the configuration file to operate on the cluster.

      This command assumes your cluster is named tutorial-cluster. If your cluster is named differently, replace all references with the name of your cluster.

    10. Set the KUBECONFIG environment variable for the ${NAMESPACE}-user-config.yaml configuration file:

      1. $ export KUBECONFIG=./${NAMESPACE}-user-config.yaml
    11. Verify that the configuration took effect by printing the current namespace:

      1. $ kubectl config view -o jsonpath="{.contexts[?(@.name==\"$(kubectl config current-context)\")].context.namespace}"
      2. tutorial

      You should see the name of your namespace in the output.

    Congratulations, you configured your cluster for the tutorial!