Showing posts with label realtime. Show all posts
Showing posts with label realtime. Show all posts

February 17, 2023

How to password pass while connect ssh in the command line

Now a days, it's very difficult remember the vm passwords while connecting in the office network. So, Connect easily using sshpass.

For installation for mac/Linux:

Mac:

brew install hudochenkov/sshpass/sshpass

Linux:

yum install sshpass


Example of usage:

Ex:

sshpass -p test123 ssh root@192.168.1.1


Reafference:

https://stackoverflow.com/questions/32255660/how-to-install-sshpass-on-mac 

Read more ...

November 16, 2022

SRIOV CNI Plugin

The Single Root I/O Virtualization (SR-IOV) specification is a standard for a type of PCI device assignment that can share a single device with multiple pods. 

SR-IOV enables you to segment a compliant network device, recognized on the host node as a physical function (PF), into multiple virtual functions (VFs), and make them available for direct IO to the POD.

This plugin enables the configuration and usage of SR-IOV VF networks in containers and orchestrators like Kubernetes. 

Network Interface Cards (NICs) with SR-IOV capabilities are managed through physical functions (PFs) and virtual functions (VFs). A PF is used by the host and usually represents a single NIC port. VF configurations are applied through the PF. With SR-IOV CNI each VF can be treated as a separate network interface, assigned to a container, and configured with it's own MAC, VLAN, IP and more.

SR-IOV CNI plugin works with SR-IOV device plugin for VF allocation in Kubernetes. A metaplugin such as Multus gets the allocated VF's deviceID(PCI address) and is responsible for invoking the SR-IOV CNI plugin with that deviceID.

The end result will be similar to the in the picture except for the SRIOV-CNI and the DPDK userspace.


Reference:

https://github.com/ramanujadasu/sriov-cni

https://dramasamy.medium.com/high-performance-containerized-applications-in-kubernetes-f494cef3f8e8

Read more ...

Understanding the Kubernetes Node

Kubernetes is an open-source orchestration engine for automating deployments, scaling, managing, and providing the infrastructure to host containerized applications. At the infrastructure level, a Kubernetes cluster is comprised of a set of physical or virtual machines, each acting in a specific role.

Master components are responsible for managing the Kubernetes cluster. They manage the life cycle of pods, the base unit of a deployment within a Kubernetes cluster. Master servers run the following components:

kube-apiserver – the main component, exposing APIs for the other master components.

etcd – distributed key/value store which Kubernetes uses for persistent storage of all cluster information.

kube-scheduler – uses information in the pod spec to decide on which node to run a pod.

kube-controller-manager – responsible for node management (detecting if a node fails), pod replication, and endpoint creation.

cloud-controller-manager – daemon acting like an abstraction layer between the APIs and the different cloud providers’ tools (storage volumes, load balancers etc.)


Node components are worker machines in Kubernetes and are managed by the Master. A node may be a virtual machine (VM) or physical machine, and Kubernetes runs equally well on both types of systems. Each node contains the necessary components to run pods:

kubelet – watches the API server for pods on that node and makes sure they are running

cAdvisor – collects metrics about pods running on that particular node

kube-proxy – watches the API server for pods/services changes in order to maintain the network up to date

container runtime – responsible for managing container images and running containers on that node


Reference:

https://www.suse.com/c/rancher_blog/understanding-the-kubernetes-node/#:~:text=kubelet%20%E2%80%93%20watches%20the%20API%20server,the%20network%20up%20to%20date

Read more ...

April 26, 2022

Create New VPN entry in Cisco AnyConnect

MacBook process to add new VPN entry:


cd /opt/cisco/anyconnect/profile

sudo cp clientprofile_old.xml clientprofile_new.xml

sudo vi clientprofile_new.xml

    Update hostname and hostaddress

    Ex:

        <ServerList>

                <HostEntry>

                        <HostName>NEW</HostName>

                        <HostAddress>127.0.0.1</HostAddress>

                </HostEntry>

         </ServerList>

 

Few mac tools for easy connect Virtual Machines:

https://mobaxterm.mobatek.net/

https://apps.apple.com/us/app/zen-term-lite-ssh-client/id1422475219?mt=12

https://iterm2.com/

 

Reference:

https://documentation.meraki.com/MX/AnyConnect_on_the_MX_Appliance/Client_deployment

Read more ...

April 15, 2022

DevOps vs GitOps

DevOps is about cultural change and providing a way for development teams and operations teams to work together collaboratively. GitOps gives you tools and a framework to take DevOps practices, like collaboration, CI/CD, and version control, and apply them to infrastructure automation and application deployment.

GitOps Free Training(LinuxFoundation):

https://trainingportal.linuxfoundation.org/learn/course/introduction-to-gitops-lfs169/course-introduction/course-information 

Reference:

https://www.redhat.com/en/topics/devops/what-is-gitops#:~:text=DevOps%20is%20about%20cultural%20change,infrastructure%20automation%20and%20application%20deployment.

Read more ...

February 16, 2022

Pushing Images to artifactory or any location of docker environment

Skopeo is a tool for moving container images between different types of container storages. It allows you to copy container images between container registries like docker.io, quay.io, and your internal container registry or different types of storage on your local system.

Below are the steps to push or pull images from artifactory using skopeo instead of docker. Skopeo is just a cli and does not require any service/privilege. No change is needed on the docker or docker-desktop settings also.


Pre-Steps: Install skopeo

brew instal skopeo

Setup proxies if any issue with environment:

export http_proxy=<hostname>:<port>

export https_proxy=<hostname>:<port>

export no_proxy="io,com,org"

Login:

skopeo login --tls-verify=false -u USERNAME <repo-url>

Inspecting a repository

skopeo inspect --config docker://quay.io/podman/stable | json_pp

Copying images

Skopeo can copy container images between various storage mechanisms:

skopeo copy docker://<imagename:latest> docker://<imagename:latest>

ex: skopeo copy docker://registry.access.redhat.com/ubi8-init docker://reg.company.com/ubi-init

skopeo copy docker://registry.fedoraproject.org/fedora:latest  containers-storage:fedora

If any restrictions repo: skopeo copy --override-arch=amd64 --override-os=linux --dest-tls-verify=false docker-daemon:<imagename:latest> docker://<imagename:latest>

Deleting images from a registry:

skopeo delete docker://localhost:5000/<imagename:latest>


Reference:

https://www.redhat.com/en/blog/skopeo-10-released#:~:text=Skopeo%20is%20a%20tool%20for,storage%20on%20your%20local%20system

Read more ...

August 23, 2021

Python sWSGI.ini applications configurations

A note on Python threads

If you start uWSGI without threads, the Python GIL will not be enabled, so threads generated by your application will never run. You may not like that choice, but remember that uWSGI is a language-independent server, so most of its choices are for maintaining it “agnostic”. But do not worry, there are basically no choices made by the uWSGI developers that cannot be changed with an option.


If you want to maintain Python threads support without starting multiple threads for your application, just add the --enable-threads option (or enable-threads = true in ini style).


Ex:
 
[uwsgi]
# -------------
# Settings:
# key = value
# Comments >> #
# -------------

strict
uid = root
gid = root

# socket = [addr:port]
http-socket = 0.0.0.0:9034

wsgi-file = app.py
callable = TEST_SERVICE

# master = [master process (true of false)]
master = true

# processes = [number of processes]
processes = 5

py-autoreload = 0

buffer-size = 32768

need-app = true
attach-daemon = celery -A app.CELERY worker --loglevel=INFO --concurrency=1

Above properties detail information available below url:

Reference:

https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html


Read more ...

Sort with given object multiple properties names, age using JAVA8

List can be sorted using Java 8 Lambda Expressions, moving right past syntactic sugar and into real and powerful functional semantics. The implementation of all of these examples and code snippets can be found over on gitHub: https://github.com/ramanujadasu/tutorials/tree/master/core-java-modules/core-java-lambdas

List<Human> humans = Lists.newArrayList(
      new Human("Sarah", 10), 
      new Human("Jack", 12)
    );


Basic Sort Without Lambdas:

    Collections.sort(humans, new Comparator<Human>() {
        @Override
        public int compare(Human h1, Human h2) {
            return h1.getName().compareTo(h2.getName());
        }
    });


Basic Sort With Lambda Support:

    humans.sort(
      (Human h1, Human h2) -> h1.getName().compareTo(h2.getName()));


Basic Sorting With No Type Definitions:

	humans.sort((h1, h2) -> h1.getName().compareTo(h2.getName()));

Sort Using Reference to Static Method:

public static int compareByNameThenAge(Human lhs, Human rhs) {
    if (lhs.name.equals(rhs.name)) {
        return Integer.compare(lhs.age, rhs.age);
    } else {
        return lhs.name.compareTo(rhs.name);
    }
}

humans.sort(Human::compareByNameThenAge);

Sort Extracted Comparators:

Collections.sort(
      humans, Comparator.comparing(Human::getName));

Reverse Sort:

Comparator<Human> comparator
      = (h1, h2) -> h1.getName().compareTo(h2.getName());
    
    humans.sort(comparator.reversed());


Sort With Multiple Conditions:

List<Human> humans = Lists.newArrayList(
      new Human("Sarah", 12), 
      new Human("Sarah", 10), 
      new Human("Zack", 12)
    );
    
    humans.sort((lhs, rhs) -> {
        if (lhs.getName().equals(rhs.getName())) {
            return Integer.compare(lhs.getAge(), rhs.getAge());
        } else {
            return lhs.getName().compareTo(rhs.getName());
        }
    });

Sort With Multiple Conditions -Composition:

humans.sort(
      Comparator.comparing(Human::getName).thenComparing(Human::getAge)
    );

Sorting a List With Stream.sorted():

List<String> letters = Lists.newArrayList("B", "A", "C");
	
List<String> sortedLetters = letters.stream().sorted().collect(Collectors.toList());
==
List<Human> humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12));
    
	Comparator<Human> nameComparator = (h1, h2) -> h1.getName().compareTo(h2.getName());
	
    	List<Human> sortedHumans = 
	      humans.stream().sorted(nameComparator).collect(Collectors.toList());

Or
  	List<Human> sortedHumans = humans.stream()
      	.sorted(Comparator.comparing(Human::getName))
      	.collect(Collectors.toList());


Sorting a List in Reverse With Stream.sorted():

List<String> letters = Lists.newArrayList("B", "A", "C");

    List<String> reverseSortedLetters = letters.stream()
      .sorted(Comparator.reverseOrder())
      .collect(Collectors.toList());
==
 List<Human> humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12));
    
	Comparator<Human> reverseNameComparator = 
      	(h1, h2) -> h2.getName().compareTo(h1.getName());

    	List<Human> reverseSortedHumans = humans.stream().sorted(reverseNameComparator)
    	 .collect(Collectors.toList());

Or
	List<Human> reverseSortedHumans = humans.stream()
      	.sorted(Comparator.comparing(Human::getName, Comparator.reverseOrder()))
     	 .collect(Collectors.toList());

Null Values:
  List<Human> humans = Lists.newArrayList(null, new Human("Jack", 12));

    humans.sort((h1, h2) -> h1.getName().compareTo(h2.getName()));
==
List<Human> humans = Lists.newArrayList(null, new Human("Jack", 12), null);

    humans.sort((h1, h2) -> {
        if (h1 == null) {
            return h2 == null ? 0 : 1;
        }
        else if (h2 == null) {
            return -1;
        }
        return h1.getName().compareTo(h2.getName());
    });

Or	
   humans.sort(Comparator.nullsLast(Comparator.comparing(Human::getName)));
Or
   humans.sort(Comparator.nullsFirst(Comparator.comparing(Human::getName)));

Reference:
https://www.baeldung.com/java-8-sort-lambda

Read more ...

Custom Marker Interface Implementation in Java

Marker interface has no method. Java has built-in marker interface like Serializable, Cloneable & Event Listener etc that are understand by JVM.

We can create our own marker interface, but it has nothing to do with JVM, we can add some checks with instanceOf.


Create the empty interface

interface Marker{    }

Write a class and implements the interface 

class A implements Marker {
  //do some task
}

Main class to check the marker interface instanceof 

class Main {
    public static void main(String[] args) {
        A ob = new A(){
        if (ob instanceof A) {
            // do some task
        }
    }
}

Reference: 
https://stackoverflow.com/questions/11008033/how-to-write-our-own-marker-interface-in-java/35278304 
https://en.wikipedia.org/wiki/Marker_interface_pattern
Read more ...

Can we use return statement in finally block in java?

Bellow program output is always 2, as we are returning 2 from the finally block. Remember the finally always executes whether there is a exception or not. So when the finally block runs it will override the return value of others. Writing return statements in finally block is not required, in fact you should not write it.

 
public class Test {
    public static int test(int i) {
        try {
            if (i == 0)
                throw new Exception();
            return 0;
        } catch (Exception e) {
            return 1;
        } finally {
            return 2;
        }
    }

    public static void main(String[] args) {
        System.out.println(test(0));
        System.out.println(test(1));
    }
}

Output:
2
2

Reference: 
https://stackoverflow.com/questions/18205493/can-we-use-return-in-finally-block

Read more ...

August 03, 2021

Profile creation and data structure concepts examples

Found few good tutorials and capture the profile building and data-structure concepts examples.

Profile creation tips and related sites:

https://github.com/ramanujadasu/golden-profile-tips/tree/main/profilecreationtips

Data structure concepts and example git repos:

https://github.com/ramanujadasu/golden-profile-tips/tree/main/datastructures

Visual view for DataStructures:

https://visualgo.net/en/bst

Java 9 Features:

https://www.youtube.com/watch?v=oRcOiGWK9Ts

Read more ...

August 01, 2021

Core Concepts and Brief Explanation



Question : Why to Override equals(Object) and hashCode() method ?
Solution: HashMap and HashSet use the hashcode value of an object to find out how the object would be stored in the collection, and subsequently hashcode is used to help locate the object in the collection. Hashing retrieval involves:
  1. First, find out the right bucket using hashCode().
  1. Secondly, search the bucket for the right element using equals()
Reference: https://www.geeksforgeeks.org/override-equalsobject-hashcode-method/
  
Question : Strategy design pattern


Solution: The strategy pattern is a Behavioral software design pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use.




Question: Advantages of MongoDB are as follows:

Solution:

  • MongoDB supports field, range-based, string pattern matching type queries. for searching the data in the database 
  • MongoDB support primary and secondary index on any fields
  • MongoDB basically uses JavaScript objects in place of procedures
  • MongoDB uses a dynamic database schema
  • MongoDB is very easy to scale up or down
  • MongoDB has inbuilt support for data partitioning (Sharding).

Reference: https://www.interviewbit.com/mongodb-interview-questions/

 

Question: Write program: get the employee salary > 10000 rupees in the provided list

Solution:

packagecom.test; 

importjava.util.*;

importjava.util.stream.Collectors;

 

publicclassTestEmployee {

        publicstaticvoidmain(String... args) {

                List<Employee> empList= newArrayList<>();

                empList.add(newEmployee("test1", 1235));

                empList.add(newEmployee("test2", 12353));

                empList.add(newEmployee("test3", 12352));

                empList.add(newEmployee("test4", 12345));

                empList.add(newEmployee("test5", 1235));

                List<String> resEmpList= empList.stream().filter(e-> e.getSalary() > 10000).map(e-> e.getName())

                                .collect(Collectors.toList());

                resEmpList.stream().forEach(System.out::println);

        }

}

 

classEmployee {

        privateString name;

        privateInteger salary;

        publicString getName() {

                return name;

        }

        publicvoidsetName(String name) {

                this.name= name;

        }

        publicInteger getSalary() {

                return salary;

        }

        publicvoidsetSalary(Integer salary) {

                this.salary= salary;

        }

        publicEmployee(String name, Integer salary) {

 

                this.name= name;

                this.salary= salary;

        }

}



Question: What is docker?

Solution:

Docker is a very popular and powerful open-source containerization platform that is used for building, deploying, and running applications. Docker allows you to decouple the application/software from the underlying infrastructure.

In order to get the status of all the containers, we run the below command:  

docker ps -a


docker save command and the syntax is: 

docker save -o <exported_name>.tar <container-name>


docker load command and the syntax is 

docker load -i <export_image_name>.tar

 

There are three docker components, they are - Docker Client, Docker Host, and Docker Registry.

  • Docker Client: This component performs “build” and “run” operations for the purpose of opening communication with the docker host.
  • Docker Host: This component has the main docker daemon and hosts containers and their associated images. The daemon establishes a connection with the docker registry.
  • Docker Registry: This component stores the docker images. There can be a public registry or a private one. The most famous public registries are Docker Hub and Docker Cloud.

Reference: https://www.interviewbit.com/docker-interview-questions/


 

Question: What is Thread life Cycle?

Solution:

The java.lang.Thread class contains a static State enum – which defines its potential states. During any given point of time, the thread can only be in one of these states:

  1. NEW – a newly created thread that has not yet started the execution
  2. RUNNABLE – either running or ready for execution but it's waiting for resource allocation
  3. BLOCKED – waiting to acquire a monitor lock to enter or re-enter a synchronized block/method
  4. WAITING – waiting for some other thread to perform a particular action without any time limit
  5. TIMED_WAITING – waiting for some other thread to perform a specific action for a specified period
  6. TERMINATED – has completed its execution 

Reference: https://www.baeldung.com/java-thread-lifecycle

 

Question: What is Hibernate Lifecycle?

Solution:

There are mainly four states of the Hibernate Lifecycle :

  1. Transient State
  2. Persistent State
  3. Detached State
  4. Removed State

Reference: https://www.geeksforgeeks.org/hibernate-lifecycle/

 


Read more ...

July 31, 2021

AWS S3 CURD Operations using spring boot

AWS S3 CURD Operations including spring boot actuator features

README file mentioned to run procedure

GITURL: https://github.com/ramanujadasu/aws-curd-apis

GIT SSH link:

git@github.com:ramanujadasu/aws-curd-apis.git


Spring Boot AWS Cloud Support

https://spring.io/projects/spring-cloud-aws#overview

 

Samples:

https://github.com/spring-cloud-samples

https://github.com/ramanujadasu/aws-refapp

Read more ...

July 28, 2021

Vertical Scaling and Horizontal Scaling

    Scaling an on-premise infrastructure is hard. You need to plan for peak capacity, wait for equipment to arrive, configure the hardware and software, and hope you get everything right the first time. But deploying your application in the cloud can address these headaches.


    Vertical scaling means that you scale by adding more power (CPU, RAM) to an existing machine. AWS provides instances up to 488 GB of RAM or 128 virtual cores.


    Horizontal scaling essentially involves adding machines in the pool of existing resources. When users grow up to 1000 or more, vertical scaling can’t handle requests and horizontal scaling is required. Horizontal scalability can be achieved with the help of clustering, distributed file system, and load balancing.


Example for horizontal scaling:


{{- if ne <value_check> "\"false\"" -}}

{{- if <value_check }}

apiVersion: autoscaling/v2beta1

kind: HorizontalPodAutoscaler

metadata:

  name: xxxx

spec:

  scaleTargetRef:

    apiVersion: apps/v1

    kind: Deployment

    name: xxxx

  minReplicas: 1 <replica_count>

  maxReplicas: 10 <max_replicas>

  metrics:

  - type: Resource

    resource:

      name: cpu

      targetAverageUtilization: 90

  - type: Resource

    resource:

      name: memory

      targetAverageUtilization: 90

{{- end }}

{{- end }}



Example for vertical scalling:


apiVersion: v1

kind: Pod

metadata:

  name: xxx-demo

  namespace: xxx-example

spec:

  containers:

  - name: xxx

    image: vish/stress

    resources:

      limits:

        memory: "2Gi"

        cpu: "2"

      requests:

        memory: "1.5Gi"

        cpu: "1.5"

    args:

    - -cpus

    - "2"


Reference:

https://devblog.axway.com/apis/helm-and-kubernetes-adoption/

https://github.com/ramanujadasu/apigw-helm-charts

https://dzone.com/articles/vertical-scaling-and-horizontal-scaling-in-aws

https://stackoverflow.com/questions/11707879/difference-between-scaling-horizontally-and-vertically-for-databases

https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/

AWS Code optimization techniques:

https://www.whizlabs.com/blog/aws-cost-optimization-best-practices/




Read more ...

My Favorite Site's List

#update below script more than 500 posts