Tuesday, 6 July 2021

Accessing kube-apiserver from a running pod / Doing a kubectl from a pod

Rarely we want our POD to talk to the kube-apiserver to fetch details about the other deployments, pod status etc. This is not a common usecase but the option provided by K8S can be used in a very creative way to solve problem when a running pod want to know information about the cluster

The logic is very simple, we use the ** kubectl ** command to talk to the kube-apiserver and access the cluster, the kubectl client maintains the details about the cluster in ~/.kube/config directory. And if we want to access the same from the pod then even the pod should contain all the configurations about the cluster so it can access the kube-apiserver

The good news is when kubernetes brings up the pod it mounts all the necessary folder that contains configuration, certificate etc and it will have one default service account attached to the pod. The default service account is authorized to access only a very limited resouce from kube-apiserver

We can create a new service account and authorize it to access additional resources by creating the following items

  1. ServiceAccount
  2. ClusterRole / Role
  3. ClusterRoleBinding / RoleBinding

Choosing between Role and ClusterRole depends on whether we want to access the resource at own namespace only or we need access resources cluster-wide

Usecase: Getting the deployment details from the POD

In this use-case, we are trying to read all the deployments available in the same namespace where the POD is running

Service Account

The first step is to create the service account, it is like a user which we will bind to the role and use it in the deployment/pod

kubectl create sa apps-sa -n vemohanr --dry-run -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  creationTimestamp: null
  name: apps-sa
  namespace: vemohanr

Role

We can create one role mentioning about all the resources we need to access or we can create one role per resource.

kubectl create role deployment-reader --verb=list,get --resource=deployment -n vemohanr --dry-run -o yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: null
  name: deployment-reader
rules:
- apiGroups:
  - apps
  resources:
  - deployments
  verbs:
  - list
  - get

Role Binding

Resource binding is the place where we will tie the service account with the role

kubectl create rolebinding apps-sa-deployment-reader --serviceaccount=vemohanr:apps-sa --role=deployment-reader -n vemohanr --dry-run -o yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  creationTimestamp: null
  name: apps-sa-deployment-reader
  namespace: vemohanr
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: deployment-reader
subjects:
- kind: ServiceAccount
  name: apps-sa
  namespace: vemohanr

Attach the Service Account to the POD

We need to attach the service account with the deployment so it will get granted access based on the role it is binded with

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: ubuntu
  name: ubuntu
  namespace: vemohanr
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ubuntu
  template:
    metadata:
      labels:
        app: ubuntu
    spec:
      serviceAccountName: apps-sa
      containers:
      - image: iad.ocir.io/paasdevoic/vemohanr/ubuntu:latest
        name: ubuntu
        command:
        - "sh"
        - "-c"
        - "sleep 10000"
      imagePullSecrets:
      - name: ocirsecret

Quick Testing

For quick testing we can get inside this ubuntu POD and execute the curl command

$ kubectl exec -it ubuntu-5d8cc9cfdf-cxzls -n vemohanr -- sh
$ APISERVER=https://kubernetes.default.svc
$ SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount
$ NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
$ TOKEN=$(cat ${SERVICEACCOUNT}/token)
$ CACERT=${SERVICEACCOUNT}/ca.crt
$ CACERT=${SERVICEACCOUNT}/ca.crt
$ curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api/apis/apps/v1/deployments

Client Libraries

There are client libraries available in most of the language and we can get info about it from https://kubernetes.io/docs/reference/using-api/client-libraries/

Reference

https://kubernetes.io/docs/tasks/run-application/access-api-from-pod/ https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

Saturday, 29 May 2021

How to grow Rose plant from cut stem

 In this post, I want to share how we can nurture the rose stem and grow it into a plant. The most important one that we need is patience because it will take 2-3 weeks at least to see the result. The real fun is on seeing how the soil and the necessary environment is giving nutrients to the cut stem and makes into a plant and we could see it growing day-by-day. 

The technique that I experimented is the greenhouse gardening technique where we will cover the whole pot inside a plastic cover so it can allow the visible light into the pot but will not allow the heat outside and keep the environment warmer.

Interesting read about the Greenhouse 

https://www.proflowers.com/blog/greenhouse-gardening-guide/
http://hyperphysics.phy-astr.gsu.edu/hbase/thermo/grnhse.html

Also since the stem do not contain the roots, we can help the stem to get root faster by using some rooting hormones. Few of the natural rooting hormones are natural honey, alovera plant gel, tulsi water etc, basically any natural product which has anti-bacterial and anti-fungal properties can be used. We can also use artificial rooting hormones as well but natural one does pretty well. The function of the rooting hormone is to protect the stem from bacteria, diseases etc. 

Interesting read about rooting harmones

https://www.urbangardengal.com/honey-rooting-hormone-cuttings/

Next is the selection of stem, we should select a healthy stem so the success rate will be high. The healthy rose stem are the one that are dark green in color without any black spots, no fungus etc. 

Lets see the process in sequence of steps

Step 1: Identify the healthy stem from the parent plant 

Step 2: Keep all the necessary tools and materials ready like the pot, scissor, knife, rooting harmone, cover etc

Step 3: Cut the stem into multiple small pieces, desirable not more than an 5-6 inches. And cut it at a 45 degree angle

Step 4: Clean the side of stem which we will insert in the soil

Step 5: Dip the side with the rooting harmone

Step 6: Keep the pot ready with right mix of soil and water. Most important info is we should not water the plant after inserting the stem, so add necessary water before inserting the stem. The reason is that if we pour water then the root harmone will disolve and get mixed into the soil.

Step 7: Insert the cut stem into the pot with some distance between them

Step 8: Cover the pot with a plastic cover and keep it in a low sunlight shade. When it is in greenhouse effect we don't have to water them everyday. The moisture will circulate within the closed area and will keep the soil wet.

Step 9: After a week we can open and check its health and cover it again

Step 10: After 2 weeks, once we see the leaves, we can make a small hole in the cover to allow leaves to get some fresh air to breath

Step 11: After 3 weeks, we can remove the greenhouse effect and either repot it or grow in the same pot

Happy Gardening!!

Wednesday, 27 January 2021

Database - Oracle Cloud Infrastructure - Architect Associate(1Z0-1072-20)

 Oracle Cloud Infrastructure Architect Associate exam tests varieties of topics like

  1. Identity and Access Management
  2. Networking
  3. Compute 
  4. Storage
  5. Database
A good place to learn about the topics are


And there is a book specifically written for the exam and is available in Oreilly




In this blog, I am sharing the notes I have taken for the topic 

Database

Storage - Oracle Cloud Infrastructure - Architect Associate(1Z0-1072-20)

 Oracle Cloud Infrastructure Architect Associate exam tests varieties of topics like

  1. Identity and Access Management
  2. Networking
  3. Compute 
  4. Storage
  5. Database
A good place to learn about the topics are


And there is a book specifically written for the exam and is available in Oreilly

In this blog, I am sharing the notes I have taken for the topic 



Storage

Compute - Oracle Cloud Infrastructure - Architect Associate(1Z0-1072-20)

  Oracle Cloud Infrastructure Architect Associate exam tests varieties of topics like

  1. Identity and Access Management
  2. Networking
  3. Compute 
  4. Storage
  5. Database
A good place to learn about the topics are


And there is a book specifically written for the exam and is available in Oreilly

In this blog, I am sharing the notes I have taken for the topic 



Compute 

Networking - Oracle Cloud Infrastructure - Architect Associate(1Z0-1072-20)

  Oracle Cloud Infrastructure Architect Associate exam tests varieties of topics like

  1. Identity and Access Management
  2. Networking
  3. Compute 
  4. Storage
  5. Database
A good place to learn about the topics are


And there is a book specifically written for the exam and is available in Oreilly

In this blog, I am sharing the notes I have taken for the topic 



Networking

IAM - Oracle Cloud Infrastructure - Architect Associate(1Z0-1072-20)

 Oracle Cloud Infrastructure Architect Associate exam tests varieties of topics like

  1. Identity and Access Management
  2. Networking
  3. Compute 
  4. Storage
  5. Database
A good place to learn about the topics are


And there is a book specifically written for the exam and is available in Oreilly

In this blog, I am sharing the notes I have taken for the topic 



Identity and Access Management (IAM)