@ -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:
To install QLKube in OpenShift, use the NodeJS Source-to-Image builder:
```sh
{{< highlight sh > }}
oc new-project qlkube --display-name=QLKube
oc new-project qlkube --display-name=QLKube
oc new-app nodejs~https://github.com/qlkube/qlkube.git --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:
Disable TLS certificate validation to accommodate your self-signed certificates:
```sh
{{< highlight sh > }}
oc set env dc/qlkube NODE_TLS_REJECT_UNAUTHORIZED=0
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):
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
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:
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
oc adm policy add-role-to-user view -z default
```
{{< / highlight > }}
Once deployed, open the QLKube URL in your web browser:
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}}")
open $(oc get route qlkube -o go-template --template="http://{{.spec.host}}")
```
{{< / highlight > }}
You can try the following queries in the GraphQL explorer.
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:**
**Query:**
```graphql
{{< highlight graphql > }}
query getAllPodsInCurrentNamespace {
query getAllPodsInCurrentNamespace {
all(namespace: "qlkube") {
all(namespace: "qlkube") {
pods {
pods {
@ -67,11 +67,11 @@ query getAllPodsInCurrentNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
**Response:**
**Response:**
```json
{{< highlight json > }}
{
{
"data": {
"data": {
"all": {
"all": {
@ -100,7 +100,7 @@ query getAllPodsInCurrentNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
## Get a service by name
## 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:**
**Query:**
```graphql
{{< highlight graphql > }}
query getServiceByNameAndNamespace {
query getServiceByNameAndNamespace {
all(namespace: "qlkube", fieldSelector: "metadata.name=qlkube") {
all(namespace: "qlkube", fieldSelector: "metadata.name=qlkube") {
services {
services {
@ -124,11 +124,11 @@ query getServiceByNameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
**Response:**
**Response:**
```json
{{< highlight json > }}
{
{
"data": {
"data": {
"all": {
"all": {
@ -148,14 +148,14 @@ query getServiceByNameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
## Type introspection
## Type introspection
Playing with the built-in types of GLKube is nice but you might soon be limited.
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:
To discover all the available types, run this query:
```graphql
{{< highlight graphql > }}
{
{
__schema {
__schema {
types {
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):
This query returns a list of all the available types (truncated here for brevity):
```json
{{< highlight json > }}
{
{
"data": {
"data": {
"__schema": {
"__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
## Get a Deployment Config by name and namespace
@ -208,7 +208,7 @@ Once the desired data type discovered, you can use it directly.
**Query:**
**Query:**
```graphql
{{< highlight graphql > }}
query getDeploymentConfigByNameAndNamespace {
query getDeploymentConfigByNameAndNamespace {
comGithubOpenshiftApiAppsV1DeploymentConfig(name: "qlkube", namespace: "qlkube") {
comGithubOpenshiftApiAppsV1DeploymentConfig(name: "qlkube", namespace: "qlkube") {
metadata {
metadata {
@ -220,11 +220,11 @@ query getDeploymentConfigByNameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
**Reponse:**
**Reponse:**
```json
{{< highlight json > }}
{
{
"data": {
"data": {
"comGithubOpenshiftApiAppsV1DeploymentConfig": {
"comGithubOpenshiftApiAppsV1DeploymentConfig": {
@ -238,7 +238,7 @@ query getDeploymentConfigByNameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
## Get routes by hostname and namespace
## 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:**
**Query:**
```graphql
{{< highlight graphql > }}
query getRouteByHostnameAndNamespace {
query getRouteByHostnameAndNamespace {
routes: comGithubOpenshiftApiRouteV1RouteList(namespace: "qlkube" fieldSelector: "spec.host=qlkube-qlkube.app.itix.fr") {
routes: comGithubOpenshiftApiRouteV1RouteList(namespace: "qlkube" fieldSelector: "spec.host=qlkube-qlkube.app.itix.fr") {
items {
items {
@ -264,11 +264,11 @@ query getRouteByHostnameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
**Reponse:**
**Reponse:**
```json
{{< highlight json > }}
{
{
"data": {
"data": {
"routes": {
"routes": {
@ -294,13 +294,13 @@ query getRouteByHostnameAndNamespace {
}
}
}
}
}
}
```
{{< / highlight > }}
## Sending your GraphQL request from curl
## 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.
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}}")
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 .
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
EOF
```
{{< / highlight > }}
## Advanced use-cases
## Advanced use-cases