Saturday, 8 August 2020

Kubernetes: Exploring livenessProbe

 One of the main benefits of Kubernetes is, when you deploy a Pod using ReplicationController (or) ReplicationSet (or) Deployment, Kubernetes make sure that the containers in the Pod are always running. If by any chance the container is killed or crashed, Kubernetes restart the container automatically.

How can Kubernetes check whether the container is in a healthy state or not?

Here the livenessProbe comes into the picture. You can specify livenessProbe of an application in the manifest file, and Kubernetes (kubelet checks) periodically execute this livenessProbe url to make sure that the container is in healthy state. If by any chance, this livenessProbe do not respond in time, then Kubernetes assumes that the container is not healthy and increase the failure count, when this failure count reaches to the certain threshold value, then Kubernetes (kubectl) initiate container restart.

 

What if a node itself crashes?

Control Pane create replacements for all the Pods it managing.

 

How to configure a livenessProbe?

There are three mechanisms to configure a livenessProbe.

 

a. Using HTTP GET API: Kubernetes execute HTTP GET request on containers IP address and port and the livenessProbe path you specified in the manifest file. If the response code is 2xx or 3xx then Kubernetes assume that the container is in healthy state, else it initiate restart.

 

b. Using TCP Socket Probe: Kubernetes tries to open a TCP connection to the specified port of the container, if the TCP connection request successful then Kubernetes assume that the container is in healthy state, else it initiate restart.

 

c. Execute arbitrary command inside the container and if the command exit code is 0 (0 represents command executed successfully) then Kubernetes assume that the container is in healthy state, else it initiate restart.

 

Let’s create a manifest file by configuring HTTP GET livenessProbe and experiment with it.

 

You can configure a livenessProbe by specifying additional parameters like failure threshold, timeout etc., For example, I configured liveness that checks application root path on container port 90.

 

livenessProbe:

  initialDelaySeconds: 10

  timeoutSeconds: 1

  failureThreshold: 3

  periodSeconds: 6

  httpGet:

    path: /

    port: 90

 

initialDelaySeconds: 10

Start Probing after 10 seconds when the container started. If you do not set initial delay, the container will get probed as soon as it starts.

 

failureThreshold: 3

Kubernetes try 3 times before giving up and restarting the pod. Giving up in case of liveness probe means restarting the container. In case of readiness probe the Pod will be marked Unready.

 

periodSeconds: 6

Container is probed for every 6 seconds.

 

timeoutSeconds: 1

Container must return a response in 1 second, otherwise Probe is counted as failed.

 

correctLivenessProbe.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-service-with-correct-liveness-probe
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: jboss/wildfly
        livenessProbe:
          initialDelaySeconds: 10
          failureThreshold: 3
          timeoutSeconds: 1
          httpGet:
            path: /
            port: 8080

Create deployment using above definition file.

$kubectl create -f correctLibenessProbe.yml 
deployment.apps/user-service-with-correct-liveness-probe created

Deployment gets created successfully, lets query Pods.

$kubectl get pods
NAME                                                        READY   STATUS    RESTARTS   AGE
user-service-with-correct-liveness-probe-79bdf8bddf-6hfdb   1/1     Running   0          42s

Pod is in Running state. Looks fine.

 

Let’s misconfigure the livenessProbe by setting it to some port where my application is not running.

 

misconfiguredLivenessProbe.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-service-with-misconfigured-liveness-probe
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: jboss/wildfly
        livenessProbe:
          initialDelaySeconds: 10
          failureThreshold: 3
          timeoutSeconds: 1
          httpGet:
            path: /
            port: 1234

As you see above snippet, I set livenessProbe GET port to 1234, but my application is running on port 8080.

 

Let’s create deployment from above manifest file.

$kubectl create -f misconfiguredLivenessProbe.yml 
deployment.apps/user-service-with-misconfigured-liveness-probe created

Let’s query for Pods.

$kubectl get pods
NAME                                                              READY   STATUS    RESTARTS   AGE
user-service-with-correct-liveness-probe-79bdf8bddf-6hfdb         1/1     Running   0          3m53s
user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw   1/1     Running   0          6s

Wait for 10 seconds (Since I configured initialDelaySeconds as 10 seconds) and query Pods again.

$kubectl get pods
NAME                                                              READY   STATUS    RESTARTS   AGE
user-service-with-correct-liveness-probe-79bdf8bddf-6hfdb         1/1     Running   0          4m42s
user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw   1/1     Running   1          55s

As you see restart count is 1 for the pod ‘user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw’.

 

Wait for some more time (more than 20 seconds), you will observe the Kubernetes tries to restart the Pod (user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw) 3 times and give up. Giving up in case of a liveness probe means restarting the container.

$kubectl get pods
NAME                                                              READY   STATUS             RESTARTS   AGE
user-service-with-correct-liveness-probe-79bdf8bddf-6hfdb         1/1     Running            0          8m58s
user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw   0/1     CrashLoopBackOff   5          5m11s
$
$kubectl get pods
NAME                                                              READY   STATUS    RESTARTS   AGE
user-service-with-correct-liveness-probe-79bdf8bddf-6hfdb         1/1     Running   0          9m23s
user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw   1/1     Running   6          5m36s

How to see the logs of the previous terminated container?

kubectl logs {mypod} --previous

 

Example

kubectl logs user-service-with-misconfigured-liveness-probe-7dd5b9fdd5-z5scw --previous



Previous                                                    Next                                                    Home

Kubernetes: Health Checks

Using ‘readinessProbe’ and ‘livenessProbe’ we can monitor the health of a container in the Pod.

'kubelet' uses readiness probes to know when a container is ready to start accepting traffic.

 

What about livenessProbe?

‘livenessProbe’ used to check prod liveess.

 

Example
livenessProbe:
  initialDelaySeconds: 10
  timeoutSeconds: 1
  httpGet:
    path: /
    port: 80

readinessProbe:
  initialDelaySeconds: 10
  httpGet:
    path: /
    port: 80

user-service-with-probe.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-service-with-probe
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: jboss/wildfly
        ports:
        - containerPort: 80
        readinessProbe:
          initialDelaySeconds: 10
          httpGet:
            path: /
            port: 80
        livenessProbe:
          initialDelaySeconds: 10
          timeoutSeconds: 1
          httpGet:
            path: /
            port: 80

Step 1: Create deployment using ‘user-service-with-probe.yml‘ file.

$kubectl create -f user-service-with-probe.yml
deployment.apps/user-service-with-probe created

Step 2: Get all pods.

$kubectl get pods
NAME                                       READY   STATUS    RESTARTS   AGE
user-service-with-probe-6b5756456f-t4gz7   0/1     Running   0          38s

This is a happy scenario. Let’s misconfigure the readiness probe and check the health.

readinessProbe:
  initialDelaySeconds: 10
  httpGet:
    path: /
    port: 90

As you see I configured readinessProbe port to 90, but the application is running on port 80. Kubernetes will check on port 90 to confirm whether the application is ready to accept the traffic.

 

user-service-with-misconfigured-ready-probe.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-service-with-misconfigured-ready-probe
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: jboss/wildfly
        ports:
        - containerPort: 80
        readinessProbe:
          initialDelaySeconds: 10
          httpGet:
            path: /
            port: 90
        livenessProbe:
          initialDelaySeconds: 10
          timeoutSeconds: 1
          httpGet:
            path: /
            port: 80
Let’s create a deployment from the file ‘user-service-with-misconfigured-ready-probe.yaml’.
$kubectl create -f user-service-with-misconfigured-ready-probe.yaml 
deployment.apps/user-service-with-misconfigured-ready-probe created

Let’s see the status of pods.

$kubectl get pods
NAME                                                           READY   STATUS    RESTARTS   AGE
user-service-with-misconfigured-ready-probe-5498fcdbb4-b9zc7   0/1     Running   0          44s
user-service-with-probe-6b5756456f-t4gz7                       1/1     Running   0          27m

As you see the output, pod ‘user-service-with-misconfigured-ready-probe-5498fcdbb4-b9zc7’ is initiated 44 seconds ago, but it is still not yet ready (0/1).

 

Let’s see more information using describe command.

 

kubectl describe pod/user-service-with-misconfigured-ready-probe-5498fcdbb4-b9zc7

 

Once you execute above command, last line of output looks like below.

 

Warning  Unhealthy  4s (x9 over 84s)  kubelet, minikube  Readiness probe failed: Get http://172.17.0.5:90/: dial tcp 172.17.0.5:90: connect: connection refused

 

From the output, you can confirm that Kubernetes check the readiness of the application 9 times over 84 seconds but it got connection refused error.

 

Misconfigure livenessProbe

livenessProbe:
  initialDelaySeconds: 10
  timeoutSeconds: 1
  failureThreshold: 3
  periodSeconds: 6
  httpGet:
    path: /
    port: 90

As you see above snippet, the application is actually running on port 80, but we are checking for the liveness on the port 90.

 

failureThreshold: 3

Kubernetes try 3 times before givingup and restarting the pod.

 

periodSeconds: 6

Perform the probe for every 6 seconds.

 

user-service-with-misconfigured-live-probe.yml

Let’s create a deployment from ‘user-service-with-misconfigured-live-probe.yml’ file.

$kubectl create -f user-service-with-misconfigured-live-probe.yml
deployment.apps/user-service-with-misconfigured-live-probe created

Let’s see the deployments.

$kubectl get deployments
NAME                                          READY   UP-TO-DATE   AVAILABLE   AGE
user-service-with-misconfigured-live-probe    1/1     1            1           33s
user-service-with-misconfigured-ready-probe   0/1     1            0           11m
user-service-with-probe                       1/1     1            1           37m

As you see ‘user-service-with-misconfigured-live-probe’ is up and running.

 

Let’s see the pod status.

$kubectl get pods
NAME                                                           READY   STATUS    RESTARTS   AGE
user-service-with-misconfigured-live-probe-7b7466b497-bwrq7    0/1     Running   3          99s
user-service-with-misconfigured-ready-probe-5498fcdbb4-b9zc7   0/1     Running   0          12m
user-service-with-probe-6b5756456f-t4gz7                       1/1     Running   0          38m

As you see the output, 3 times restart is initiated for the pod ‘user-service-with-misconfigured-live-probe-7b7466b497-bwrq7’.

 

Wait for some time and query the pods again.

$kubectl get pods
NAME                                                           READY   STATUS             RESTARTS   AGE
user-service-with-misconfigured-live-probe-7b7466b497-bwrq7    0/1     CrashLoopBackOff   4          2m48s
user-service-with-misconfigured-ready-probe-5498fcdbb4-b9zc7   0/1     Running            0          13m
user-service-with-probe-6b5756456f-t4gz7                       1/1     Running            0          39m

You will observe that the pod state is set to ‘CrashLoopBackOff’.



Previous                                                    Next                                                    Home

Kubernetes: Labels: Working with Selectors

 Label selectors are used to identify a group of objects.

Types of selectors

a.   Equality Based Selector: =, !=

b.   Set-Based Selector: IN, NONIN, EXISTS

 

selectors.yml
apiVersion: v1
kind: Pod
metadata:
  name: user-management-service
  labels:
    env: dev
    author: Krishna
    application_type: service
    team: Marketting
    release-version: "1.23"
spec:
  containers:
  - name: user-management-service
    image: jboss/wildfly
---
apiVersion: v1
kind: Pod
metadata:
  name: domain-managemet-service
  labels:
    env: dev
    author: chamu
    application_type: service
    team: HR
    release-version: "1.25"
spec:
  containers:
  - name: domain-management-service
    image: jboss/wildfly
---
apiVersion: v1
kind: Pod
metadata:
  name: content-management-service
  labels:
    env: prod
    author: krishna
    application_type: service
    team: Finance
    release-version: "7.5"
spec:
  containers:
  - name: content-management-service
    image: jboss/wildfly

Step 1: Create a resource from a file ‘selectors.yml’ by executing the below command.

kubectl create -f selectors.yml
$kubectl create -f selectors.yml 
pod/user-management-service created
pod/domain-managemet-service created
pod/content-management-service created

= and != operator

a. Get all the prods where the environment is prod

kubectl get pods --selector env=prod

$kubectl get pods --selector env=prod
NAME                         READY   STATUS    RESTARTS   AGE
content-management-service   1/1     Running   0          80s

b. Get all the prods where the environment is not prod

kubectl get pods --selector env!=prod

$kubectl get pods --selector env!=prod
NAME                       READY   STATUS    RESTARTS   AGE
domain-managemet-service   1/1     Running   0          4m20s
user-management-service    1/1     Running   0          4m20s

IN Operator

kubectl get pods -l 'release-version in (1.23, 7)' --show-labels

$kubectl get pods -l 'release-version in (1.23, 7)' --show-labels
NAME                      READY   STATUS    RESTARTS   AGE     LABELS
user-management-service   1/1     Running   0          4m20s   application_type=service,author=Krishna,env=dev,release-version=1.23,team=Marketting

NOT IN Operator

kubectl get pods -l 'release-version notin (1.23, 7)' --show-labels

$kubectl get pods -l 'release-version notin (1.23, 7)' --show-labels
NAME                         READY   STATUS    RESTARTS   AGE     LABELS
content-management-service   1/1     Running   0          5m13s   application_type=service,author=krishna,env=prod,release-version=7.5,team=Finance
domain-managemet-service     1/1     Running   0          5m13s   application_type=service,author=chamu,env=dev,release-version=1.25,team=HR


Previous                                                    Next                                                    Home

Friday, 7 August 2020

Kubernetes: Working with labels

 Step 1: Define .yml file with some labels.

labels-demo.yml

apiVersion: v1
kind: Pod
metadata:
  name: user-service
  labels:
    env: dev
    author: Krishna
    application_type: service
    release-version: "1.0"
spec:
  containers:
  - name: user-service
    image: jboss/wildfly

Following labels are defined in the above yml file.

env: dev

         author: Krishna

application_type: service

         release-version: "1.0"

 

Step 2: Create a resource from a file ‘labels-demo.yml’.

$kubectl create -f labels-demo.yml 
pod/user-service created

Step 3: View labels associated with pod using the below command.

kubectl get pods --show-labels

$kubectl get pods --show-labels
NAME           READY   STATUS    RESTARTS   AGE    LABELS
user-service   1/1     Running   0          2m1s   application_type=service,author=Krishna,env=dev,release-version=1.0

How to add labels to the already deployed pod?

Below command add new label ‘support=true’

 

kubectl label pod/user-service support=true

$kubectl label pod/user-service support=true
pod/user-service labeled
$
$kubectl get pods --show-labels
NAME           READY   STATUS    RESTARTS   AGE    LABELS
user-service   1/1     Running   0          6m7s   application_type=service,author=Krishna,env=dev,release-version=1.0,support=true


How to override existing labels?

Use --overwrite option to override existing labels.

 

For example, below statement override the author's name to chamu.

kubectl label pod/user-service author=chamu --overwrite

$kubectl label pod/user-service author=chamu --overwrite
pod/user-service labeled
$
$kubectl get pods --show-labels
NAME           READY   STATUS    RESTARTS   AGE     LABELS
user-service   1/1     Running   0          7m43s   application_type=service,author=chamu,env=dev,release-version=1.0,support=true

How to delete a label?

Below statement delete the label ‘support’.

 

kubectl label pod/user-service support-

$kubectl label pod/user-service support-
pod/user-service labeled
$
$kubectl get pods --show-labels
NAME           READY   STATUS    RESTARTS   AGE   LABELS
user-service   1/1     Running   0          10m   application_type=service,author=chamu,env=dev,release-version=1.0




Previous                                                    Next                                                    Home

Kubernetes: Delete Everything from current namespace

 Execute below command to delete everything from the current namespace.

kubectl delete all --all

$kubectl delete all --all
pod "hello-node-59fddbb58-h5mgt" deleted
pod "hello-node-59fddbb58-rv8wt" deleted
pod "hello-node-59fddbb58-s2lrj" deleted
pod "hello-node-from-file-c67467bd7-8xq6d" deleted
pod "user-service-67b679f45f-bllwj" deleted
service "hello-node" deleted
service "hello-node-from-file" deleted
service "helloworld-all-service" deleted
service "kubernetes" deleted
service "user-service" deleted
deployment.apps "hello-node" deleted
deployment.apps "hello-node-from-file" deleted
deployment.apps "user-service" deleted
replicaset.apps "user-service-67b679f45f" deleted

You can confirm the same by executing ‘kubelet get *’ commands.

$kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   59s
$
$kubectl get deployments
No resources found in default namespace.
$
$kubectl get rs
No resources found in default namespace.
$
$kubectl get pods
No resources found in default namespace.





Previous                                                    Next                                                    Home

Kubernetes: list all pods, replicasets, services and deployments

Execute the command ‘kubectl get all’ to list all pods, replicasets, services and deployments.
$kubectl get all
NAME                                              READY   STATUS    RESTARTS   AGE
pod/employee-service-deployment-dff6c9cdf-2wrg9   1/1     Running   0          9m13s
pod/employee-service-deployment-dff6c9cdf-8m7cr   1/1     Running   0          9m13s
pod/employee-service-deployment-dff6c9cdf-kv9ck   1/1     Running   0          9m13s
pod/employee-service-deployment-dff6c9cdf-pbfpr   1/1     Running   0          9m13s
pod/employee-service-deployment-dff6c9cdf-s4nh4   1/1     Running   0          9m13s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   28d

NAME                                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/employee-service-deployment   5/5     5            5           9m13s

NAME                                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/employee-service-deployment-dff6c9cdf   5         5         5       9m13s




Previous                                                    Next                                                    Home

Tuesday, 4 August 2020

Talk to Kubernetes API Server using CURL command

You can talk to Kubernetes API server in 3 ways.a

a.   Using kubectl command

b.   Kubernetes Dashboard

c.    Any rest client like Postman, curl

 

API server provides REST Apis to communicate with it. You can create Kubernetes objects like Pods, ReplicaSets, Deployments, etc., by talking to API Server.

 

 

Let’s talk to Kubernetes using curl command-line tool.

 

Step 1: In order to communicate using curl, first you need to start kubectl proxy.

 

kubectl proxy --port=1234

Above command starts a proxy on port 1234.

$kubectl proxy --port=1234
Starting to serve on 127.0.0.1:1234

You can run the proxy in background by adding & at the end of the command.

 

kubectl proxy --port=1234 &

 

Step 2: Communicate to the proxy using curl.

 

Execute the command ‘curl http://localhost:1234’ to see all the APIs provided by kubectl proxy.

$curl http://localhost:1234
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/",
    "/apis/admissionregistration.k8s.io",
    "/apis/admissionregistration.k8s.io/v1",
    "/apis/admissionregistration.k8s.io/v1beta1",
    "/apis/apiextensions.k8s.io",
    "/apis/apiextensions.k8s.io/v1",
    "/apis/apiextensions.k8s.io/v1beta1",
    "/apis/apiregistration.k8s.io",
    "/apis/apiregistration.k8s.io/v1",
    "/apis/apiregistration.k8s.io/v1beta1",
    "/apis/apps",
    "/apis/apps/v1",
    "/apis/authentication.k8s.io",
    "/apis/authentication.k8s.io/v1",
    "/apis/authentication.k8s.io/v1beta1",
    "/apis/authorization.k8s.io",
    "/apis/authorization.k8s.io/v1",
    "/apis/authorization.k8s.io/v1beta1",
    "/apis/autoscaling",
    "/apis/autoscaling/v1",
    "/apis/autoscaling/v2beta1",
    "/apis/autoscaling/v2beta2",
    "/apis/batch",
    "/apis/batch/v1",
    "/apis/batch/v1beta1",
    "/apis/certificates.k8s.io",
    "/apis/certificates.k8s.io/v1beta1",
    "/apis/coordination.k8s.io",
    "/apis/coordination.k8s.io/v1",
    "/apis/coordination.k8s.io/v1beta1",
    "/apis/discovery.k8s.io",
    "/apis/discovery.k8s.io/v1beta1",
    "/apis/events.k8s.io",
    "/apis/events.k8s.io/v1beta1",
    "/apis/extensions",
    "/apis/extensions/v1beta1",
    "/apis/networking.k8s.io",
    "/apis/networking.k8s.io/v1",
    "/apis/networking.k8s.io/v1beta1",
    "/apis/node.k8s.io",
    "/apis/node.k8s.io/v1beta1",
    "/apis/policy",
    "/apis/policy/v1beta1",
    "/apis/rbac.authorization.k8s.io",
    "/apis/rbac.authorization.k8s.io/v1",
    "/apis/rbac.authorization.k8s.io/v1beta1",
    "/apis/scheduling.k8s.io",
    "/apis/scheduling.k8s.io/v1",
    "/apis/scheduling.k8s.io/v1beta1",
    "/apis/storage.k8s.io",
    "/apis/storage.k8s.io/v1",
    "/apis/storage.k8s.io/v1beta1",
    "/healthz",
    "/healthz/autoregister-completion",
    "/healthz/etcd",
    "/healthz/log",
    "/healthz/ping",
    "/healthz/poststarthook/apiservice-openapi-controller",
    "/healthz/poststarthook/apiservice-registration-controller",
    "/healthz/poststarthook/apiservice-status-available-controller",
    "/healthz/poststarthook/bootstrap-controller",
    "/healthz/poststarthook/crd-informer-synced",
    "/healthz/poststarthook/generic-apiserver-start-informers",
    "/healthz/poststarthook/kube-apiserver-autoregistration",
    "/healthz/poststarthook/rbac/bootstrap-roles",
    "/healthz/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/healthz/poststarthook/start-apiextensions-controllers",
    "/healthz/poststarthook/start-apiextensions-informers",
    "/healthz/poststarthook/start-cluster-authentication-info-controller",
    "/healthz/poststarthook/start-kube-aggregator-informers",
    "/healthz/poststarthook/start-kube-apiserver-admission-initializer",
    "/livez",
    "/livez/autoregister-completion",
    "/livez/etcd",
    "/livez/log",
    "/livez/ping",
    "/livez/poststarthook/apiservice-openapi-controller",
    "/livez/poststarthook/apiservice-registration-controller",
    "/livez/poststarthook/apiservice-status-available-controller",
    "/livez/poststarthook/bootstrap-controller",
    "/livez/poststarthook/crd-informer-synced",
    "/livez/poststarthook/generic-apiserver-start-informers",
    "/livez/poststarthook/kube-apiserver-autoregistration",
    "/livez/poststarthook/rbac/bootstrap-roles",
    "/livez/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/livez/poststarthook/start-apiextensions-controllers",
    "/livez/poststarthook/start-apiextensions-informers",
    "/livez/poststarthook/start-cluster-authentication-info-controller",
    "/livez/poststarthook/start-kube-aggregator-informers",
    "/livez/poststarthook/start-kube-apiserver-admission-initializer",
    "/logs",
    "/metrics",
    "/openapi/v2",
    "/readyz",
    "/readyz/autoregister-completion",
    "/readyz/etcd",
    "/readyz/log",
    "/readyz/ping",
    "/readyz/poststarthook/apiservice-openapi-controller",
    "/readyz/poststarthook/apiservice-registration-controller",
    "/readyz/poststarthook/apiservice-status-available-controller",
    "/readyz/poststarthook/bootstrap-controller",
    "/readyz/poststarthook/crd-informer-synced",
    "/readyz/poststarthook/generic-apiserver-start-informers",
    "/readyz/poststarthook/kube-apiserver-autoregistration",
    "/readyz/poststarthook/rbac/bootstrap-roles",
    "/readyz/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/readyz/poststarthook/start-apiextensions-controllers",
    "/readyz/poststarthook/start-apiextensions-informers",
    "/readyz/poststarthook/start-cluster-authentication-info-controller",
    "/readyz/poststarthook/start-kube-aggregator-informers",
    "/readyz/poststarthook/start-kube-apiserver-admission-initializer",
    "/readyz/shutdown",
    "/version"
  ]
}

curl http://localhost:1234/metrics

Give you the metrics

 

curl http://localhost:1234/version

Give you the version information.

$curl http://localhost:1234/version
{
  "major": "1",
  "minor": "18",
  "gitVersion": "v1.18.0",
  "gitCommit": "9e991415386e4cf155a24b1da15becaa390438d8",
  "gitTreeState": "clean",
  "buildDate": "2020-03-25T14:50:46Z",
  "goVersion": "go1.13.8",
  "compiler": "gc",
  "platform": "linux/amd64"
}

curl http://localhost:1234/api/v1/namespaces

Give all the available namespaces.

 

curl http://localhost:1234/api/v1/namespaces/default/services

List all the services in the default namespace.

 

curl http://localhost:1234/api/v1/namespaces/default/pods

List all the available pods in the default namespace.

 

Let’s create a deployment and explore the API objects using curl tool.

 

Step 1: Create employeeServiceDeployment.yml with the below content.

 

employeeServiceDeployment.yml

metadata:
  name: employee-service-deployment
  labels:
    app: employee-service-deployment
    author: krishna
    serviceType: webservice
spec:
  template:
    metadata:
      name: employee-service
      labels:
        app: employee-service
        author: krishna
        serviceType: webservice
    spec:
      containers:
      - name: employee-service-container
        image: jboss/wildfly

  replicas: 5
  selector:
    matchLabels:
      app: employee-servic

As you see above definition, it creates 5 pods with the image ‘jboss/wildfly’.

 

Step 2: Create deployment by executing below command.

 

kubectl create -f employeeServiceDeployment.yml

$kubectl create -f employeeServiceDeployment.yml
deployment.apps/employee-service-deployment created

Step 3: You can query the pods information by executing below command.

curl http://localhost:1234/api/v1/namespaces/default/pods

 

I hope you got some basic idea and now you can go through Kubernetes documentation and explore the APIs.




Previous                                                    Next                                                    Home