Creating a Kubernetes Cluster

Perform the following steps to create a Kubernetes cluster.

Note: Cluster deployment requires root level privileges in order for the Mashery Local containers to run. Log in as root to perform the tml-cluster deployment.

Procedure

  1. Navigate to the folder docker-deploy/onprem/k8s/manifest-single-zone and execute the following command:
    ./create-local-k8s-cluster.sh
    This creates a local Kubernetes cluster consisting of one Kubernetes master node and the number of worker nodes you specified in the manifest-single-zone.json. Default cluster consists of one Kubernetes master and one worker node and it takes around 15 minutes. The script also deletes any previous kube configuration file at the location ~/.kube/config and creates a new configuration file for the newly-created cluster at this location so that you can execute any kubectl command from your terminal. Also, make sure you can ping the VMs with the IP (192.168.99.110, in case of default) from your local machine. If not, please resolve this first. The issue could be related with VirtualBox networking.
  2. Verify that the cluster is created successfully by running the following command. Status should be Ready for all the nodes. Do not proceed until all the nodes are in Ready status.
    kubectl get nodes
    Sample output for 1 master and 2 nodes:
    NAME      STATUS    ROLES     AGE       VERSION
    
    master    Ready     master    7m        v1.10.5
    
    node-1    Ready     <none>    4m        v1.10.5
    
    Note: Important! If you modified the k8s_deploy_namespace to deploy Mashery Local 5.2 in a specific namespace in k8s cluster, you need to configure kubectl again for the given namespace. After running the above command, your kube config file (~/.kube/config) will have entry for the GCP k8s cluster and user as shown below.
    apiVersion: v1
    clusters:
    - cluster:
        certificate-authority-data: XYZ
        server: https://<K8S Server>
      name: gke_mashery-local-51
    contexts:
    - context:
        cluster: gke_mashery-local-51
        user: gke_mashery-local-51
      name: gke_mashery-local-51
    current-context: gke_mashery-local-51
    kind: Config
    preferences: {}
    users:
    - name: gke_mashery-local-51
      user:
        auth-provider:
          config:
            cmd-args: config config-helper --format=json
            cmd-path: /Users/Ashkumar/Downloads/google-cloud-sdk/bin/gcloud
            expiry-key: '{.credential.token_expiry}'
            token-key: '{.credential.access_token}'
          name: gcp
    
    

    Note down the value of cluster and user.

    Execute the following commands to create a new context for the namespace you want to deploy and configure kubectl to use the new context:
    1. kubectl config set-context <conext-name>
      --namespace=<namespace_value provided in the
      manifest-single-zone.json> --cluster=<k8s cluster name >
      --user=<k8s user>
      Sample command:
      kubectl config set-context mashery-dev --namespace=mashery
      --cluster=gke_mashery-local-51 --user=gke_mashery-local-51
    2. kubectl config use-context <context-name>
      Sample command:
      kubectl config use-context mashery-dev
  3. If the namespace you provided in manifest-single-zone.json is not present in k8s cluster, run the following command first to create the namespace:
    ./create-tml-namespace.sh
  4. If you are using external registry, you need to perform Docker login first:
    docker login <registry host> -u <user> -p <password>
    Example:
    docker login mashbuilder-1.na.acme.com -u admin -p <pwd>
    Make sure the login is successful and then execute the following script:
    ./set-registry-secret.sh