Giter Club home page Giter Club logo

qlkube's Introduction

Otel in Practice demo with Graphql

This demo is using :

  • a modified version of the project Qlkube
  • the openTelemetry demo
  • the OpenTelemetry Operator
  • Dynatrace

Deployment Steps in GCP

You will first need a Kubernetes cluster with 2 Nodes. You can either deploy on Minikube or K3s or follow the instructions to create GKE cluster:

1.Create a Google Cloud Platform Project

PROJECT_ID="<your-project-id>"
gcloud services enable container.googleapis.com --project ${PROJECT_ID}
gcloud services enable monitoring.googleapis.com \
    cloudtrace.googleapis.com \
    clouddebugger.googleapis.com \
    cloudprofiler.googleapis.com \
    --project ${PROJECT_ID}

2.Create a GKE cluster

ZONE=europe-west3-a
NAME=otelinpractice-qlkube
gcloud container clusters create "${NAME}" \
 --zone ${ZONE} --machine-type=e2-standard-2 --num-nodes=3

Getting started

Dynatrace Tenant

1. Dynatrace Tenant - start a trial

If you don't have any Dyntrace tenant , then i suggest to create a trial using the following link : Dynatrace Trial Once you have your Tenant save the Dynatrace (including https) tenant URL in the variable DT_TENANT_URL (for example : https://dedededfrf.live.dynatrace.com)

DT_TENANT_URL=<YOUR TENANT URL>

2. Create the Dynatrace API Tokens

Create a Dynatrace token with the following scope ( left menu Acces Token):

  • ingest metrics
  • ingest OpenTelemetry traces

data token

Save the value of the token . We will use it later to store in a k8S secret
DATA_INGEST_TOKEN=<YOUR TOKEN VALUE>

3.Clone the Github Repository

git clone https://github.com/henrikrexed/qlkube
cd qlkube

4.Deploy most of the components

The application will deploy the otel demo v1.2.1

chmod 777 deployment.sh
./deployment.sh  --clustername "${NAME}" --dturl "${DT_TENANT_URL}" --dttoken "${DATA_INGEST_TOKEN}"

Qlkube

qlkube is a graphql api for kubernetes, allowing you to interact with all the features of the Kubernetes api using graphql.

qlkube's graphql schema is dynamically built from the openapi/swagger api specification exposed by the Kubernetes cluster it is running in - qlkube should therefore:

  • expose all the types and operations from the Kubernetes rest api in its grapqhl api
  • be consistent with the exact Kubernetes api version of your cluster and kept up to date if and when this changes

In addition to the directly mapped operations from the openapi spec, qlkube provides an 'all' query type that gives a more natural 'kubectl' influenced interface into the api.

qlkube ships with the Apollo GraphQL Playground, so you can play around with the api straight away.

Demo

Example Queries

The 'all' resource is the easiest query type to use for querying kubernetes resources of all types (services, pods, deployments etc). qlkube also exposes all the low-level resources autogenerated from the Kubernetes openapi/swagger api - these types are named exactly as the 'operationId' in the openapi spec, they can therefore seem quite 'low-level' and sometimes unintuitive in comparison.

Get all pods in all namespaces

This query returns the names and namespaces of all the pods in the cluster. (here we use the more friendly 'all' type - you can perform a similar query using listCoreV1PodForAllNamespaces)

query getAllPodsInAllNamespaces {
  all {
    pods {
      items {
        metadata {
          name
          namespace
        }
      }
    }
  }
}

Output:

{
  "data": {
    "all": {
      "pods": {
        "items": [
          {
            "metadata": {
              "name": "alpha-7c766f4fc7-2bh8m",
              "namespace": "default"
            }
          },
          {
            "metadata": {
              "name": "alpha-7c766f4fc7-hx8ml",
              "namespace": "default"
            }
          },
          {
            "metadata": {
              "name": "alpha-7c766f4fc7-ztpph",
              "namespace": "default"
            }
          },
          {
            "metadata": {
              "name": "beta-v1-597679f796-k5gn4",
              "namespace": "default"
            }
          },
          {
            "metadata": {
              "name": "beta-v1-597679f796-x7hsl",
              "namespace": "default"
            }
          },
          {
            "metadata": {
              "name": "gamma-79bc488b5b-srmxm",
              "namespace": "default"
            }
          },
...etc
Get all pods in a specific namespace

This query returns the names, namespaces, creation times and labels of all the pods in the 'default' namespace (here we use the more friendly 'all' type - you can perform a similar query using ioK8sApiCoreV1PodList)

query getAllPodsInDefaultNamespace {
  all(namespace: "default") {
    pods {
      items {
        metadata {
          name
          namespace
          creationTimestamp
          labels
        }
      }
    }
  }
}

Output:

{
  "data": {
    "all": {
      "pods": {
        "items": [
          {
            "metadata": {
              "name": "alpha-7c766f4fc7-2bh8m",
              "namespace": "default",
              "creationTimestamp": "2019-06-03T15:07:17Z",
              "labels": {
                "app": "alpha",
                "appKubernetesIoManagedBy": "skaffold-v0.29.0",
                "appId": "github.expedia.biz_hotels_alpha",
                "podTemplateHash": "7c766f4fc7",
                "skaffoldDevBuilder": "local",
                "skaffoldDevCleanup": "true",
                "skaffoldDevDeployer": "kubectl",
                "skaffoldDevDockerApiVersion": "1.39",
                "skaffoldDevTagPolicy": "git-commit",
                "skaffoldDevTail": "true",
                "version": "v1"
              }
            }
          },
...etc          
Get all kubernetes resources with a specific label

This query gets the names of all kubernetes resources (services, deployments, pods etc) that are labelled with label 'app=alpha' (roughly equivalent to kubectl get all -l app=alpha)

query allResourcesOfApp {
  all(labelSelector:"app=alpha") { 
    services {
      items {
        metadata {
          name
        }
      }
    }
    deployments {
      items {
        metadata {
          name
        }
      }
    }
    pods {
      items {
        metadata {
          name
        }
      }
    }
    daemonSets {
      items {
        metadata {
          name
        }
      }
    }
    replicaSets {
      items {
        metadata {
          name
        }
      }
    }
    statefulSets {
      items {
        metadata {
          name
        }
      }
    }
    jobs {
      items {
        metadata {
          name
        }
      }
    }
    cronJobs {
      items {
        metadata {
          name
        }
      }
    } 
    namespaces {
      items {
        metadata {
          name
        }
      }
    }
  }
}

Output:

{
  "data": {
    "all": {
      "services": {
        "items": [
          {
            "metadata": {
              "name": "alpha"
            }
          }
        ]
      },
      "deployments": {
        "items": [
          {
            "metadata": {
              "name": "alpha"
            }
          }
        ]
      },
      "pods": {
        "items": [
          {
            "metadata": {
              "name": "alpha-7c766f4fc7-2bh8m"
            }
          },
...etc          

Example Mutations

Create namespace

This mutation creates a new 'bar' namespace. The input json is the escaped version of the following:

{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "name": "bar"
    }
}

We output the creation timestamp for the new namesapce.

mutation createNamespace {
  createCoreV1Namespace(input: "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"name\":\"bar\"}}") {
    metadata {
      creationTimestamp
    }
  }
}

Output:

{
  "data": {
    "createCoreV1Namespace": {
      "metadata": {
        "creationTimestamp": "2019-06-03T22:37:02Z"
      }
    }
  }
}

qlkube's People

Contributors

henrikrexed avatar nea1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.