Posts

Storage in kubernetes

 CNI(Container Storage Interface): here Reclaim policy in pv: 3 types of reclaims  1.Retain 2.Delete 3.Recycle(It is depricated) In case of dynamic provisioning, default re-claim policy is delete i.e when you delete pvc then pv is deleted and also associated data in storage providers(GCP,NFS,Azure File etc) also gets deleted. But incase of retain, when we delete pvc, pv and actual storage both are not deleted.We need to delete both of them manually. If a pv is already created using claim reuest by dynamic provisioning, we can change re-claim policy of that pv to retain by applying path as shown below: kubectl patch pv <your-pv-name> -p "{\"spec\":{\"persistentVolumeReclaimPolicy\":\"Retain\"}}" Note: In case of dynamic provisioning using nfs, there is a filed called archieveonDelete in class.yaml file,which is by default set to false.So if we change that to true when we delete pv,then its actual storage is still retained in nfs server as ar...

Authentication and Authorisation in Kubernetes

 Authentication and Authorisation in Kubernetes: Who wants to talk to kubernetes cluster??? Either a user or an application. So if an user or application want to talk to kubernetes cluster, He needs auhentication and authorisation. Authentication: If an user needs to talk to k8 cluster, the authentication is provided by kubeconfig file For example, if a user named admin wants to talk to k8 cluster, he needs kubernetes config file, the default location of this file is( ~/.kube/config ) This file contains the information of  1.User  2.Cluster  3.Context Generally admin user, manages who wants to communicate with cluster by creating seperate config files for each user(This is in theory in practice all the developers users the same admin config file,which he shares with all the developers with in the team, by editing namespace) If any one want to authenticate to kube api server, he needs 3 things 1.ca.crt(certificate of CA, local to the cluster) 2.user.crt(User certifica...

Kubernetes CKAD

Image
 Configuration: In Docker | In kubernetes yaml file CMD - args ENTRYPOINT - command The command opton specified in yaml file will overide the entry point specified in docker file,same with the case of args Config maps: blog 1.Create config map imperative way: 2.Declare in a separate yaml file in declarative way as shown below and use in pod definition file: 3. Use only single key property or use in volumes Secrets: It is not good practice to store sensitive information in configmap, so we use secrets sytanxes of both looks like almost same 1.Creating secrets using imperative way 2.Creating  secrets using declarative way 3.Use only single key property or use in volumes 4.we didn't store actual passwords,we use base64 encoding, see below 5.we can decode base64 encoded strings as below 6. viewing secret maps Security context: Blog If we want to add specific capabilties to containers,we can add in pod-definition file as shown below We can do the same in docker from docker run comm...

Kubernetes more ...

Image
Create an NGINX Pod kubectl run nginx --image=nginx Generate POD Manifest YAML file (-o yaml). Don't create it(--dry-run) kubectl run nginx --image=nginx --dry-run=client -o yaml Create a deployment kubectl create deployment --image=nginx nginx Generate Deployment YAML file (-o yaml). Don't create it(--dry-run) kubectl create deployment --image=nginx nginx --dry-run=client -o yaml Generate Deployment YAML file (-o yaml). Don't create it(--dry-run) with 4 Replicas (--replicas=4) kubectl create deployment --image=nginx nginx --dry-run=client -o yaml > nginx-deployment.yaml Save it to a file, make necessary changes to the file (for example, adding more replicas) and then create the deployment. kubectl create -f nginx-deployment.yaml OR In k8s version 1.19+, we can specify the --replicas option to create a deployment with 4 replicas. kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml Note: if we don't want to c...

Kubernetes

Image
1. Basic commands: kubectl run nginx --image=nginx  - gets the nginx image from the docker repository and launches apod with name nginx in cluster. kubectl get nodes - to get list of nodes kubectl describe pod nginx - gets all the properties of pod with nane nginx,like container id,ip address of pod and ip address of node etc kubectl delete pods <pod name> - To delete pods kubectl delete replicasets <replicaset name> -  To delete replica sets kubectl delete deployments <deployment name> - To delete deployments -------------------------------  kubectl delete --all svc --namespace=default - To delete all services in a namespace at once,similary pods,replicasets and deployments replace svc with pods,rc and deploy respectively  2. Pods: Every thing about pods like creating pods using kubectl,using yaml file and remove those etc,nice blog here 3.Replica set: blog: here video: here we can edit replaceset yaml definition file using and use kubectl replace ...

Kubernetes installation

 In RHEL family distribution using minicube: here Install kubernetes using kubeadm in centos7 - here

Docker Swarm

Image
 Docker swarm: docker swarm init   - This will start swarm service and the host in which ypu executed this command will become leader   - It will give some result and we need to paste that code in worker nodes and we ned to enable 2377              port for communication  docker swarm leave - The node will come out of cluster Docker service commands: 1.docker service create -p 80:80 --replicas=3 --name=web --niginx If we don't specify any replicas by default 1 service will be created 2. docker service ls It will list services 3. docker service  ps web  List the tasks of one or more services, it will display information of service like on which workers how many instances are running and which is leader,reachable and worker etc, if we do docker inspect of taskID,we can see many more details 4. docker service scale web=3 we can scale or descale number of instances of service running by giving its number 5. docker service insp...