Quantcast
Channel: DevOps tips & tricks
Viewing all articles
Browse latest Browse all 181

MicroK8s - deploy sample app

$
0
0

MicroK8s quick start guide 



Get nodes

[dave@localhost ~]$ microk8s.kubectl get nodes

NAME                    STATUS   ROLES    AGE   VERSION

localhost.localdomain   Ready    <none>   24h   v1.17.2

 


Get services

[dave@localhost ~]$ microk8s.kubectl get services

NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE

kubernetes   ClusterIP   10.152.183.1   <none>        443/TCP   24h

 


[dave@localhost ~]$ microk8s.kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

deployment.apps/kubernetes-bootcamp created

 

[dave@localhost ~]$ microk8s.kubectl get pods

NAME                                   READY   STATUS    RESTARTS   AGE

kubernetes-bootcamp-69fbc6f4cf-f2vvk   1/1     Running   0          41s

 

Get deployments

[dave@localhost ~]$ kubectl get deployments

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE

kubernetes-bootcamp   1/1     1            1           7m12s

 


Get pod name

[dave@localhost ~]$ export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

[dave@localhost ~]$ echo Name of the Pod: $POD_NAME

Name of the Pod: kubernetes-bootcamp-69fbc6f4cf-f2vvk

 


Describe pods
[dave@localhost ~]$ kubectl describe pods

Name:         kubernetes-bootcamp-69fbc6f4cf-f2vvk

Namespace:    default

Priority:     0

Node:         localhost.localdomain/192.168.0.116

Start Time:   Sun, 09 Feb 2020 08:53:15 +0100

Labels:       app=kubernetes-bootcamp

              pod-template-hash=69fbc6f4cf

Annotations:  <none>

Status:       Running

IP:           10.1.30.34

IPs:

  IP:           10.1.30.34

Controlled By:  ReplicaSet/kubernetes-bootcamp-69fbc6f4cf

Containers:

  kubernetes-bootcamp:

    Container ID:   containerd://e1c171143d299f88fb686f83e2fa2aae1cbe59e14cff53f4f332c2ccc2fb3f2e

    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1

    Image ID:       gcr.io/google-samples/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af

    Port:           <none>

    Host Port:      <none>

    State:          Running

      Started:      Sun, 09 Feb 2020 08:53:26 +0100

    Ready:          True

    Restart Count:  0

    Environment:    <none>

    Mounts:

      /var/run/secrets/kubernetes.io/serviceaccount from default-token-msp2q (ro)

Conditions:

  Type              Status

  Initialized       True 

  Ready             True 

  ContainersReady   True 

  PodScheduled      True 

Volumes:

  default-token-msp2q:

    Type:        Secret (a volume populated by a Secret)

    SecretName:  default-token-msp2q

    Optional:    false

QoS Class:       BestEffort

Node-Selectors:  <none>

Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s

                 node.kubernetes.io/unreachable:NoExecute for 300s

Events:

  Type    Reason     Age   From                            Message

  ----    ------     ----  ----                            -------

  Normal  Scheduled  11m   default-scheduler               Successfully assigned default/kubernetes-bootcamp-69fbc6f4cf-f2vvk to localhost.localdomain

  Normal  Pulling    11m   kubelet, localhost.localdomain  Pulling image "gcr.io/google-samples/kubernetes-bootcamp:v1"

  Normal  Pulled     11m   kubelet, localhost.localdomain  Successfully pulled image "gcr.io/google-samples/kubernetes-bootcamp:v1"

  Normal  Created    11m   kubelet, localhost.localdomain  Created container kubernetes-bootcamp

  Normal  Started    11m   kubelet, localhost.localdomain  Started container kubernetes-bootcamp

 


Explore introduction https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/

Get logs from pod

[dave@localhost ~]$ kubectl logs $POD_NAME

Kubernetes Bootcamp App Started At: 2020-02-09T07:53:26.300Z | Running On:  kubernetes-bootcamp-69fbc6f4cf-f2vvk 

 
 


Exec commands on pod

[dave@localhost ~]$ kubectl exec $POD_NAME env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

HOSTNAME=kubernetes-bootcamp-69fbc6f4cf-f2vvk

NPM_CONFIG_LOGLEVEL=info

NODE_VERSION=6.3.1

KUBERNETES_PORT=tcp://10.152.183.1:443

KUBERNETES_PORT_443_TCP=tcp://10.152.183.1:443

KUBERNETES_PORT_443_TCP_PROTO=tcp

KUBERNETES_PORT_443_TCP_PORT=443

KUBERNETES_PORT_443_TCP_ADDR=10.152.183.1

KUBERNETES_SERVICE_HOST=10.152.183.1

KUBERNETES_SERVICE_PORT=443

KUBERNETES_SERVICE_PORT_HTTPS=443

HOME=/root

 


Run bash in pod
[dave@localhost ~]$ kubectl exec -ti $POD_NAME bash

root@kubernetes-bootcamp-69fbc6f4cf-f2vvk:/# cat server.js

var http = require('http');

var requests=0;

var podname= process.env.HOSTNAME;

var startTime;

var host;

var handleRequest = function(request, response) {

  response.setHeader('Content-Type', 'text/plain');

  response.writeHead(200);

  response.write("Hello Kubernetes bootcamp! | Running on: ");

  response.write(host);

  response.end(" | v=1\n");

  console.log("Running On:" ,host, "| Total Requests:", ++requests,"| App Uptime:", (new Date() - startTime)/1000 , "seconds", "| Log Time:",new Date());

}

var www = http.createServer(handleRequest);

www.listen(8080,function () {

    startTime = new Date();;

    host = process.env.HOSTNAME;

    console.log ("Kubernetes Bootcamp App Started At:",startTime, "| Running On: " ,host, "\n" );

});

root@kubernetes-bootcamp-69fbc6f4cf-f2vvk:/# curl localhost:8080

Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-69fbc6f4cf-f2vvk | v=1

 






Viewing all articles
Browse latest Browse all 181

Trending Articles