@ -14,34 +14,34 @@ It is very useful for mobile application and web development: by reducing the nu
To install QLKube in OpenShift, use the NodeJS Source-to-Image builder:
```sh
{{< highlight sh > }}
oc new-project qlkube --display-name=QLKube
oc new-app nodejs~https://github.com/qlkube/qlkube.git --name=qlkube
```
{{< / highlight > }}
Disable TLS certificate validation to accommodate your self-signed certificates:
```sh
{{< highlight sh > }}
oc set env dc/qlkube NODE_TLS_REJECT_UNAUTHORIZED=0
```
{{< / highlight > }}
And enable the NodeJS development mode to enable the GraphQL explorer (disabled in production mode):
```sh
{{< highlight sh > }}
oc set env dc/qlkube NODE_ENV=development
```
{{< / highlight > }}
Give the GLKube's Service Account the right to query the Kubernetes API for its own namespace:
```sh
{{< highlight sh > }}
oc adm policy add-role-to-user view -z default
```
{{< / highlight > }}
Once deployed, open the QLKube URL in your web browser:
```sh
{{< highlight sh > }}
open $(oc get route qlkube -o go-template --template="http://{{.spec.host}}")
```
{{< / highlight > }}
You can try the following queries in the GraphQL explorer.
@ -51,7 +51,7 @@ Unless you gave the `cluster-admin` right to the QLKube Service Account, you wil
**Query:**
```graphql
{{< highlight graphql > }}
query getAllPodsInCurrentNamespace {
all(namespace: "qlkube") {
pods {
@ -67,11 +67,11 @@ query getAllPodsInCurrentNamespace {
}
}
}
```
{{< / highlight > }}
**Response:**
```json
{{< highlight json > }}
{
"data": {
"all": {
@ -100,7 +100,7 @@ query getAllPodsInCurrentNamespace {
}
}
}
```
{{< / highlight > }}
## Get a service by name
@ -108,7 +108,7 @@ To get an object by name, you can use the `fieldSelector` parameter (in this exa
**Query:**
```graphql
{{< highlight graphql > }}
query getServiceByNameAndNamespace {
all(namespace: "qlkube", fieldSelector: "metadata.name=qlkube") {
services {
@ -124,11 +124,11 @@ query getServiceByNameAndNamespace {
}
}
}
```
{{< / highlight > }}
**Response:**
```json
{{< highlight json > }}
{
"data": {
"all": {
@ -148,14 +148,14 @@ query getServiceByNameAndNamespace {
}
}
}
```
{{< / highlight > }}
## Type introspection
Playing with the built-in types of GLKube is nice but you might soon be limited.
To discover all the available types, run this query:
```graphql
{{< highlight graphql > }}
{
__schema {
types {
@ -163,11 +163,11 @@ To discover all the available types, run this query:
}
}
}
```
{{< / highlight > }}
This query returns a list of all the available types (truncated here for brevity):
```json
{{< highlight json > }}
{
"data": {
"__schema": {
@ -197,7 +197,7 @@ This query returns a list of all the available types (truncated here for brevity
}
}
}
```
{{< / highlight > }}
## Get a Deployment Config by name and namespace
@ -208,7 +208,7 @@ Once the desired data type discovered, you can use it directly.
**Query:**
```graphql
{{< highlight graphql > }}
query getDeploymentConfigByNameAndNamespace {
comGithubOpenshiftApiAppsV1DeploymentConfig(name: "qlkube", namespace: "qlkube") {
metadata {
@ -220,11 +220,11 @@ query getDeploymentConfigByNameAndNamespace {
}
}
}
```
{{< / highlight > }}
**Reponse:**
```json
{{< highlight json > }}
{
"data": {
"comGithubOpenshiftApiAppsV1DeploymentConfig": {
@ -238,7 +238,7 @@ query getDeploymentConfigByNameAndNamespace {
}
}
}
```
{{< / highlight > }}
## Get routes by hostname and namespace
@ -246,7 +246,7 @@ This query use a `fieldSelector` on the `host` field in the `spec` section and u
**Query:**
```graphql
{{< highlight graphql > }}
query getRouteByHostnameAndNamespace {
routes: comGithubOpenshiftApiRouteV1RouteList(namespace: "qlkube" fieldSelector: "spec.host=qlkube-qlkube.app.itix.fr") {
items {
@ -264,11 +264,11 @@ query getRouteByHostnameAndNamespace {
}
}
}
```
{{< / highlight > }}
**Reponse:**
```json
{{< highlight json > }}
{
"data": {
"routes": {
@ -294,13 +294,13 @@ query getRouteByHostnameAndNamespace {
}
}
}
```
{{< / highlight > }}
## Sending your GraphQL request from curl
Once your GraphQL queries refined in the GraphQL Explorer, you can send them directly using curl or any HTTP client.
```sh
{{< highlight sh > }}
export GLKUBE_HOSTNAME=$(oc get route qlkube -o go-template --template="{{.spec.host}}")
cat < < EOF | curl -XPOST " http: / / $ GLKUBE_HOSTNAME / " -H " Content-Type: application / json " -d @ - -s | jq .
@ -321,7 +321,7 @@ cat <<EOF | curl -XPOST "http://$GLKUBE_HOSTNAME/" -H "Content-Type: application
}"
}
EOF
```
{{< / highlight > }}
## Advanced use-cases