Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Sunday, August 16, 2020

Java Interview @ Rocketalk: Part-2

Hi Friends,

In this post, I am sharing interview questions asked in Rocketalk: Round - 2. 



Question 1:

What is Docker swarm?

Answer:

A docker swarm is a group of either physical or virtual machines that are running the docker application and that have been configured to join together in a cluster.

Docker swarm is a container orchestration tool, meaning that it allows the user to manage multiple containers deployed across multiple host machines.

The cluster management and orchestration features embedded in the docker engine are built using swarmkit.

Swarmkit is a separate project which implements docker's orchestration layer and is used directly within docker.

A swarm consists of multiple docker hosts  which run in swarm mode and act as managers[to manage membership and delegation] and workers[which run swarm services].

A given docker host can be a manager, a worker or perform both roles.

When we create a service, we define it's optimal state(number of replicas, network and storage resources available to it, ports the service exposes to the outside world and more).

Docker works to maintain that desired state. For instance, if a worker node becomes unavailable, docker schedules that node's tasks on other nodes. A task is a running container which is part of a swarm service and managed by a swarm manager, as opposed to a standalone container.


One of the key advantages of swarm services over standalone containers is that we can modify a service's configuration including the networks and volumes it is connected to, without the need to manually restart the service. Docker will update the configuration, stop the service tasks with the out of date configuration and create new ones matching the desired configuration.


When docker is running in swarm mode, we can still run standalone containers on any of the docker hosts participating in the swarm, as well as swarm services. 

A key difference between swarm services and standalone containers is that only swarm managers can manage a swarm, while standalone containers can be started on any daemon. Docker daemons can participate in a swarm as a managers, workers or both. 

In the same way that we can use docker compose to define and run containers, we can define and run swarm services stacks. 


Question 2:

What is the difference between Kubernetes and Docker Swarm?

Answer:

Kubernetes: Kubernetes is an open source platform created by google for container deployment operations, scaling up and down and automation across the clusters of hosts. This production-ready, enterprise grade, self healing(auto-scaling, auto-replication, auto-restart, auto-replacement) platform is modular and so it can be utilized for any architecture deployment.


Kubernetes also distributes the load amongst containers. It aims to relieve the tools and components from the problem faced due to running applications in private and public clouds by placing the containers into groups and naming them as logical units. Their power lies in easy scaling, environment agnostic portability and flexible growth.


Docker Swarm:

As a platform, docker has revolutionized the manner software was packaged. Docker swarm or simply swarm is an open-source container orchestration platform and is the native clustering engine for and by docker. Any software, services or tools that run with docker containers run equally well in swarm. Also swarm utilizes the same command line from docker.


Docker Swarm tuns a pool of docker hosts into a virtual, single host. Swarm is especially useful for people who are trying to get comfortable with an orchestrated environment or who need to adhere to a simple deployment technique but also have more just one cloud environment or one particular platform to run this on.

Kubernetes versus Docker Swarm:


Application definition:

Kubernetes:  An application can be deployed in Kubernetes utilizing a combination of services (or microservices), deployments and pods.


Docker Swarm: The applications can be deployed as micro-services or services in a swarm cluster in Docker swarm. YAML files can be utilized to identify multi-container. Moreover, Docker compose can install the application.



Networking:

Kubernetes: The networking model is a flat network, allowing all pods to interact with one another. The network policies specifies how the pods interact with each other. The flat network is implemented typically as an overlay. The model needs to CIDRs one for the services and another from which pods acquire an IP address.


Docker Swarm:

The node joining a swarm cluster generates an overlay network for services that span every host in the docker swarm and a host-only docker bridge network for containers. The users have a choice to encrypt container data traffic while creating of an overlay network by on their own in docker swarm. 


Scalability:

Kubernetes: For distributed systems, kubernetes is more of an all-in-one framework. It is a complex system because it provides strong guarantees about the cluster state and a unified set of APIs. This slows down container scaling and deployment.

Docker Swarm: Docker Swarm, when compared to Kubernetes, can deploy container much faster and this allows faster reaction times to scale on demand.



Question 3:

What is the difference between execute(), executeQuery() and executeUpdate() methods?

Answer:

Definition of execute() is boolean execute(String sql) throws SQLException.

This method can be used for all types of SQL statements. If you do not know which method to use for SQL statements, this method can be the best option. This method returns a boolean value. TRUE indicates that statement has returned a ResultSet object and FALSE indicates that statement has returned an int value or returned nothing.


Definition of executeQuery() is :

ResultSet executeQuery(String sql) throws SQLException.

This method is used for sql statements which retrieve some data from the database. For example is Select statement. This method is meant to be used for select queries which fetch some data from the database. This method returns one java.sql.ResultSet object which contains the data returned by the query.


Definition of executeUpdate() is :

int executeUpdate(String sql) throws SQLException

This method is used for SQL statements which update the database in some way. For example UPDATE and DELETE statements.

This method returns an int value which represents the number of rows affected by the query. This value will be 0 for the statements which return nothing.



Question 4:

What is the use of spring-boot-starter-parent?

Answer:

It provides default configurations for our application and a complete dependency tree to quickly build our spring boot project.

It also provides default configurations for maven plugins such as maven-failsafe-plugin, maven-jar-plugin, maven-surefire-plugin, maven-war-plugin.

Beyond that it also inherits dependency management from spring-boot-dependencies which is the parent to the spring-boot-starter-parent. 


We can start using it in our project by adding this as a parent in our project's pom.xml file.

<parent>

    <groupId>org.psringframework.boot<.groupId>

    <artifactId> spring-boot-starter-parent</artifactId>

    <version>2.2.6.RELEASE</version>

</parent>


Once we have declared the starter parent in our project, we can pull any dependency from the parent by just declaring it in our dependencies tag.

Also, we do not need to define versions of the dependencies, maven will download jar files based on the version defined for starter parent in the parent tag.



Question 5:

Where does spring store the cached data?

Answer:

Spring stores the data in internal tables.

If any value is cached for some input parameter [function argument], then that method is not called and the cached value is returned for that request.

@Cacheable(cacheNames = "cacheName") : This name is very important. It is the name of the cache.

When we want to delete all the entries in any cache , use @CacheEvict(cacheName = "cacheName", allEntries = true).

We can also tell spring that only cache values for input which is greater than some value. e.g.:

@Cacheable(cacheNames = "cacheName", condition = "#id > 1").


Question 6:

What are java microservices frameworks?

Answer:

There are many java microservices frameworks available:

  • Spring and Spring Boot
  • DropWizard
  • Eclipse MicroProfiler


Spring and Spring Boot:

The framework propagates building the application into a jar and running it on the embedded tomcat server, making it a perfect combination with Docker to manage a virtualized deployment environment.


DropWizard:

Like spring boot, dropwizard applications are packaged into fat jar files with the jetty application server embedded.

DropWizard integrates the tried-and-tested java libraries into a fully functional platform: Jersey for REST, Jackson for JSON.

For Templates, it uses Freemarker and Mustache is available for java-based UIs.

DropWizard ships with no built-in dependency injection solution, but integration exists for Guice and Dagger.


That's all for this post.

Thanks for reading!!

Wednesday, June 10, 2020

Docker Interview questions

Hi Friends,

In this post , I'm sharing few questions-answers asked on Docker knowledge.



Question 1:

What is Portainer? What are it's uses?


Answer:

Portainer is an open source management UI for Docker including Docker swarm environment.

Portainer makes it easier for managing docker images, containers, networks and volumes from the web-based portainer dashboard.

Portainer consists of a single container that can run on any Docker engine.



Question 2:

What is docker and how does it work?

Answer:

Docker is a set of Platform as a Service  products that uses OS level virtualization to deliver softwares in packages called containers.

Docker resolves any compatibility issue that might occur in the versions of multiple services with the OS version.

With Docker , we are able to run each component /service in separate container with all it's dependencies and libraries and all on the same VM and OS.



Question 3:

What is container?

Answer:

Containers are completely isolated environments. They can have their own processes for services, their own network interfaces except that they all share the OS kernel.

Containers are not new with Docker. Containers have existed for about more than 10 years now and there are different types of containers : LX c , LX d etc.

Docker uses LX c types of containers.   

Setting up these container environment is very hard as they are very low level and that is where docker offers a high level tool with several powerful functionalities making it really easy for end-users.



Question 4:

List some useful docker commands with their purpose.

Answer:

docker run <imagename> :
  • docker run command is used to run a container from the image. e.g. : running the docker run nginx will run an instance of nginx application from the docker host if it already exists. If the image is not present on the docker host, then it will go out to docker hub and pull the image down. But this is only done for the first time. For the subsequent executions , the same image will be reused.

docker ps:
  • docker ps command lists all running containers and some basic information about them such as container ID, the name of the image we used to run container, the current status and name of the container.

docker ps -a:
  • It shows all running as well as previously stopped or exited containers.

docker stop <container name>
  • This command is used to stop the container and we need to provide either the container ID or container name.

docker rm <container name>
  • This command is used to remove any existed container permanently. Note: If this command prints the name back, we are good.

docker images:
  • This command prints a list of available images and their sizes.

docker rmi <imagename>
  • This command is used to remove any image that we are not supposed to use anymore.

docker pull <image name>
  • This command is used when we only want to pull the image and not to run it.

docker --version:
  • This command is used to get the currently installed version of docker.

docker exec:
  • This command is used to access the running container.


Question 5:

What is the difference between docker kill and docker stop?

Answer:

docker kill command kills the container by stopping its execution immediately.
While the docker stop command gives the container time to shutdown gracefully, in situations when it is taking too much time for getting the container to stop. 




That's all for this post.
Thanks for reading!!

CAP Theorem and external configuration in microservices

 Hi friends, In this post, I will explain about CAP Theorem and setting external configurations in microservices. Question 1: What is CAP Th...