Monday, 27 August 2018

Common Linux Commands for Beginners

Similar to the Command Prompt in Windows, Linux has the Terminal in order to help you configure and interact with your system. For someone to work in the Terminal they need to familiarize themselves with Linux commands. Once familiarized it is fairly easy to work from the Terminal and that is why most of the Linux workers prefer the Linux terminal over the GUI.

This article will help you to get familiarized with all the most common Linux commands and their usages. These commands are divided into 15 sections based on their functionalities.

System Related Commands

These commands are used to view and manage Linux system-related information.
1. uname                   :  Displays linux system information. With -a switch you can view all the information, with -r switch you can view kernel release information and with -o you can view OS information
2. cat /etc/redhat_release :  Shows which version of redhat installed 
3. uptime                  :  Shows how long the system has been running
4. hostname                :  Shows system host name. With -i switch you can view the ip address of the machine and with -d you can view the domain name
5. last reboot             :  Shows system reboot history
6. date                    :  Shows the current date and time. You can specify the format you want to view the date as well. As an example, by using 'date +%D' you can view the date in 'MM/DD/YY' format
7. cal                     :  Shows the calendar of the current month. With -y switch you can view the calendar of the whole current year
8. w                       :  Displays who is logged on and what they are doing
9. whoami                  :  Shows current user id
10. finger user            :  Displays information about user
11. reboot                :  Reboots the system
12. shutdown              :  Shuts down the system

Hardware Related Commands

These commands are used to view and manage hardware-related aspects of the Linux machine.
13. dmesg                 : Displays all the messages from Kernel ring buffer. With -k switch you can view kernel messages and with -u you can view userspace messages
14. cat /proc/cpuinfo     : Displays information about processes and CPUs of the system
15. cat /proc/meminfo     : Displays details on hardware memory
16. cat /proc/interrupts  : Lists the number of interrupts per CPU per I/O device
17. lshw                  : Displays information on hardware configuration of the system. But this command must be run as super user or it will only report partial information
18. lsblk                 : Displays block device related information of the machine. With -a you can view all block devices
19. free -m               : Shows used and free memory (-m for MB)
20. lspci -tv             : Shows information on PCI buses devices
21. lsusb -tv             : Shows information on USB devices
22. dmidecode             : Shows hardware info from the BIOS (vendor details)
23. hdparm -i /dev/sda    : Shows info about disk sda
    hdparm -tT /dev/sda   : Performs a read speed test on disk sda
24. badblocks -s /dev/sda : Tests for unreadable blocks on disk sda

Statistic Related Commands

These set of commands are used to view various kinds of stats of the Linux system
25. mpstat 1                      : Displays processors related statistics
26. vmstat 2                      : Displays virtual memory statistics
27. iostat 2                      : Displays I/O statistics
28. tail -n 500 /var/log/messages : Displays the last 500 kernel/syslog messages
29. tcpdump -i eth1               : Captures all packets flow on interface eth1. With -w switch you can specify a file where you can direct the output to
    tcpdump -i eth0 'port 80'     : Monitors all traffic on port 80 on interface eth0
30. lsof                          : Lists all open files belonging to all active processes
    lsof -u testuser              : Lists files opened by a specific user
31. free -m                       : Shows RAM memory details
32. watch df -h                   : Watches changeable disk usage continuously

User-Related Commands

These commands are used to manage Linux users
33. id                                      : Shows the active user and group information. With -G switch you can view the IDs of groups
34. last                                    : Shows a list of last logins on the system. Using -a switch you can add the hostname to the last column of the output
35. who                                     : Shows who is logged on the system
36. groupadd admin                          : Adds the group "admin"
37. useradd -c "Sam Tomshi" -g admin -m sam : Creates user "sam" and adds to group "admin"
38. userdel sam                             : Deletes user sam
39. adduser sam                             : Adds user "sam"
40. usermod                                 : Modifies user information
41. passwd user1                            : Changes the password of user1

File Related Commands

These commands are used to handle files and directories
42. ls -al                                 : Displays all information about files/directories. This includes displaying all hidden files as well
43. pwd                                    : Shows current directory path
44. mkdir directory-name                   : Creates a directory
45. rm file-name                           : Deletes file
    rm -r directory-name                   : Deletes directory recursively 
    rm -f file-name                        : Forcefully removes file
    rm -rf directory-name                  : Forcefully removes directory recursively
46. cp file1 file2                         : Copies linux files, here file1 to file2
    cp -r dir1 dir2                        : Copies dir1 to dir2, creates dir2 if it doesn't  exist
47. mv file1 file2                         : Moves files from one place to another/renames file1 to file2
48. ln -s  /path/to/file-name link-name    : Creates a symbolic link to file-name
49. touch file                             : Creates empty file
50. cat file                               : Prints the file content in terminal
51. more file                              : Display the contents of file
52. head file                              : Display the first 10 lines of file
53. tail file                              : Outputs the last 10 lines of file
    tail -f file                           : Outputs the contents of file as it grows starting with the last 10 lines
54. gpg -c file                            : Encrypts file
    gpg file.gpg                           : Decrypts file
55. cksum file                             : View the checksum of the file
56. diff file1 file2                       : View the differences between contents of file1 and file2
57. ln -s link file                        : Create a soft link named link to the file
58. sort                                   : Sorts files in alphabetical order
59. uniq                                   : Compares adjacent lines in a file and removes/reports any duplicate lines
60. wc                                     : Counts number of words/lines
61. dir                                    : Lists the content of the directory
62. tee                                    : Command for chaining and redirection
63. tr                                     : Command for translating characters

Process Related Commands

These commands are used to handle Linux processes
64. ps                       : Displays your currently active processes
    ps aux | grep 'telnet'   : Displays all process ids related to telnet process
65. pmap                     : Display Memory map of process
66. top                      : Display all running processes and cpu/memory usage
67. kill pid                 : Kills process with mentioned pid
68. killall proc             : Kills all processes named proc
69. pkill processname        : Sends kill signal to a process with its name
70. bg                       : Resumes suspended jobs without bringing them to foreground
71. fg                       : Brings the most recent job to foreground
    fg n                     : Brings job n to the foreground

File Permission Related Commands

These commands are used to change permissions of the files
72. chmod octal file-name             : Changes the permissions of file to octal
    chmod 777 /data/test.c                   : Sets rwx permission for owner , group and others
    chmod 755 /data/test.c                   : Sets rwx permission for owner and rx for group and others
73. chown owner-user file                    : Changes owner of the file
    chown owner-user:owner-group  file-name  : Changes owner and group owner of the file
    chown owner-user:owner-group directory   : Changes owner and group owner of the directory
74. chgrp group1 file                        : Changes the group ownership of the file to group1

Network Related Commands

These commands are used to view and edit network configurations related aspects of the system
75. ifconfig -a        : Displays all network interface and set ip address
76. ifconfig eth0      : Displays eth0 ethernet port ip address and details
77. ip addr show       : Display all network interfaces and ip addresses
78. ip address add 192.168.0.1 dev eth0  : Sets ip address of eth0 device
79. ethtool eth0       : Linux tool to show ethernet status
80. mii-tool  eth0     : Linux tool to show eth0 status
81. ping host          : Sends echo requests to the host to test ipv4 connection
82. whois domain       : Gets who is information for domain
83. dig domain         : Gets DNS nameserver information for domain
    dig -x host        : Reverse lookup host 
84. host google.com    : Lookup DNS ip address for the name
85. hostname -i        : Lookup local ip address
86. wget file          : Downloads file
87. netstat  -tupl     : Lists all active listening ports
88. nslookup           : Resolves domain names to IP addresses

Compression / Archive Related Commands

These commands are used to compress and decompress files
89. tar cf home.tar  home         : Creates a tar named home.tar containing home/
    tar xf file.tar               : Extracts the files from file.tar
    tar czf  file.tar.gz  files   : Creates a tar with gzip compression
90. gzip file                     : Compresses file and renames it to file.gz
91. bzip2 -z file                 : Compresses file and renames it to file.bz2
    bzip2 -d file.bz2             : Decompress the file

Package Installation Related Commands

These commands are used to manage Linux packages
92. rpm -i pkgname.rpm     : Installs rpm based package
    rpm -e pkgname         : Removes package
93. make                   : Install from source file

Search Related Commands

These commands are used to search for files and patterns
94. grep pattern files              : Searches for pattern in files
    grep -r pattern dir             : Searches recursively for pattern in dir
95. locate file                     : Finds all instances of file
96. find /home/tom -name 'index*'   : Finds file names that start with "index" inside /home/tom directory
    find /home -size +10000k        : Finds files larger than 10000k in /home

Login Related Commands

These commands are used to log into another host
97. ssh user@host              : Securely connect to a host as user
    ssh -p port $ user@host    : Connects to host using specific port
98. telnet host                : Connects to the system using  telnet port

File Transfer Related Commands

These commands are used to copy files from one system to another system
99. scp file.txt   server2:/tmp                  : Secure copy file.txt to remote host  /tmp folder
    scp nixsavy@server2:/www/*.html /www/tmp     : Copies *.html files from remote host to current host /www/tmp folder
    scp -r nixsavy@server2:/www   /www/tmp       : Copies all files and folders recursively from remote server to the current system /www/tmp folder
100. rsync -a /home/apps /backup/                 : Synchronizes source to destination
    rsync -avz /home/apps $ linoxide@192.168.10.1:/backup  : Synchronize files/directories between the local and remote system with compression enabled

Disk Usage Related Commands

These commands are used to view disk statistics
101.  df -h                          : Shows free space on mounted filesystems
     df -i                      : Shows free inodes on mounted filesystems
102. fdisk -l                     : Shows disks partitions sizes and types
103. du -ah                         : Displays disk usage in human readable form
     du -sh                         : Displays total disk usage on the current directory
104. findmnt                        : Displays target mount point for all filesystems
105. mount device-path mount-point  : Mounts a device to the device-path

Directory Traverse Related Commands

These commands are used to change the directory
106. cd ..          : Goes up one level of the directory tree
     cd             : Goes to $HOME directory
     cd /test       : Changes to /test directory

Saturday, 25 August 2018

Kubernetes Interview Questions And Answers

Kubernetes Interview Questions
Kubernetes is anOpen source software
Kubernetes is aSystem for automating deployment, scaling and management of containerized applications
Kubernetes wasOriginally designed by Google and now maintained by the Cloud Native Computing Foundation.
Kubernetes canIt aims to provide a platform for automating deployment, scaling, and operations of application containers.
Kubernetes developed byGoogle
Kubernetes LicenseApache License 2.0
Kubernetes has written inGo Programming
Kubernetes Interview Question # 1) What is the Kubernetes?
A) Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery. 

Kubernetes Interview Question # 2) What is Kubernetes and how to use it?
A) Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. With Kubernetes, you are able to quickly and efficiently respond to customer demand: Deploy your applications quickly and predictably.

Kubernetes Interview Question # 3) What is the meaning of Kubernetes?
A) Kubernetes (commonly referred to as “K8s”) is an open-source system for automating deployment, scaling and management of containerized applications that was originally designed by Google and donated to the Cloud Native Computing Foundation.

Docker Kubernetes Interview Questions For Experienced

Kubernetes Interview Question # 4) What is a docker?
A) Docker container is an open source software development platform. Its main benefit is to package applications in “containers,” allowing them to be portable among any system running the Linux operating system (OS).

Kubernetes Interview Question # 5) What is orchestration in software?
A) Application Orchestration. Application or service orchestration is the process of integrating two or more applications and/or services together to automate a process, or synchronize data in real-time. Often, point-to-point integration may be used as the path of least resistance.

Kubernetes Questions # 6) What is a cluster in Kubernetes?
A) These master and node machines run the Kubernetes cluster orchestration system. A container cluster is the foundation of Container Engine: the Kubernetesobjects that represent your containerized applications all run on top of a cluster.

Interview Questions on Kubernetes # 7) What is a swarm in Docker?
A) Docker Swarm is a clustering and scheduling tool for Docker containers. With Swarm, IT administrators and developers can establish and manage a cluster ofDocker nodes as a single virtual system.

Kubernetes Openshift Interview Question # 8) What is Openshift?
A) OpenShift Online is Red Hat’s public cloud application development and hosting platform that automates the provisioning, management and scaling of applications so that you can focus on writing the code for your business, startup, or big idea.

Advanced Kubernetes Interview Questions

Docker and Kubernetes Interview Question # 9) What is a namespace in Kubernetes?
A) Namespaces are intended for use in environments with many users spread across multiple teams, or projects. Namespaces are a way to divide cluster resources between multiple uses (via resource quota). In future versions of Kubernetes, objects in the same namespace will have the same access control policies by default.

Kubernetes Interview Question # 10) What is a node in Kubernetes?
A) A node is a worker machine in Kubernetes, previously known as a minion. A nodemay be a VM or physical machine, depending on the cluster. Each node has the services necessary to run pods and is managed by the master components. The services on a node include Docker, kubelet and kube-proxy.

Kubernetes Interview Question # 11) What is Docker and what does it do?
A) Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Kubernetes Interview Question # 12) What is a Heapster?
A) Heapster is a cluster-wide aggregator of monitoring and event data. It supports Kubernetes natively and works on all Kubernetes setups, including our Deis Workflow setup.

Kubernetes Interview Question # 13) Why do we use Docker?
A) Docker provides this same capability without the overhead of a virtual machine. It lets you put your environment and configuration into code and deploy it. The same Docker configuration can also be used in a variety of environments. This decouples infrastructure requirements from the application environment.

Kubernetes Interview Question # 14) What is a docker in cloud?
A) A node is an individual Linux host used to deploy and run your applications. Docker Cloud does not provide hosting services, so all of your applications, services, and containers run on your own hosts. Your hosts can come from several different sources, including physical servers, virtual machines or cloud providers.

Kubernetes Interview Question # 15) What is a cluster of containers?
A) A container cluster is a set of Compute Engine instances called nodes. It also creates routes for the nodes, so that containers running on the nodes can communicate with each other. The Kubernetes API server does not run on your cluster nodes. Instead, Container Engine hosts the API server.

Real-Time Kubernetes Scenario Based Interview Questions

Kubernetes Interview Questions # 16) What is the Kubelet?
A) Kubelets run pods. The unit of execution that Kubernetes works with is the pod. A pod is a collection of containers that share some resources: they have a single IP, and can share volumes.

Kubernetes Interview Questions # 17) What is Minikube?
A) Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

Kubernetes Interview Questions # 18) What is Kubectl?
A) kubectl is a command line interface for running commands against Kubernetes clusters. This overview covers kubectl syntax, describes the command operations, and provides common examples. For details about each command, including all the supported flags and subcommands, see the kubectl reference documentation.

Kubernetes Interview Questions # 19) What is the Gke?
A) Google Container Engine (GKE) is a management and orchestration system for Docker container and container clusters that run within Google’s public cloud services. Google Container Engine is based on Kubernetes, Google’s open source container management system.

Kubernetes Interview Questions # 20) What is k8s?
A) Kubernetes, also sometimes called K8S (K – eight characters – S), is an open source orchestration framework for containerized applications that was born from the Google data centers.

Kubernetes Interview Questions # 21) What is KUBE proxy?
A) Synopsis. The Kubernetes network proxy runs on each node. Service cluster ips and ports are currently found through Docker-links-compatible environment variables specifying ports opened by the service proxy. There is an optional addon that provides cluster DNS for these cluster IPs.

Kubernetes Interview Questions # 22) Which process runs on Kubernetes master node?
A) Kube-apiserver process runs on Kubernetes master node.

Kubernetes Interview Questions # 23) Which process runs on Kubernetes non-master node?
A) Kube-proxy process runs on Kubernetes non-master node.

Kubernetes Interview Questions # 24) Which process validates and configures data for the api objects like pods, services?
A) kube-apiserver process validates and configures data for the api objects.

Kubernetes Interview Questions # 25) What is the use of kube-controller-manager?
A) kube-controller-manager embeds the core control loop which is a non-terminating loop that regulates the state of the system.

Kubernetes Interview Questions # 26) Kubernetes objects made up of what?
A) Kubernetes objects are made up of Pod, Service and Volume.

Kubernetes Interview Questions # 27) What are Kubernetes controllers?
A) Kubernetes controllers are Replicaset, Deployment controller.

Kubernetes Interview Questions # 28) Where Kubernetes cluster data is stored?
A) etcd is responsible for storing Kubernetes cluster data.

Kubernetes Interview Questions # 29) What is the role of kube-scheduler?
A) kube-scheduler is responsible for assigning a node to newly created pods.

Kubernetes Interview Questions # 30) Which container runtimes supported by Kubernetes?
A) Kubernetes supports docker and rkt container runtimes.

Kubernetes Interview Questions # 31) What are the components interact with Kubernetes node interface?
A) Kubectl, Kubelet, and Node Controller components interacts with Kubernetes node interface.

Q: What is Kubernetes?
A:
 Kubernetes is Google's open source system for managing Linux containers across private, public and hybrid cloud environments.
It is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. 
It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available. It contains tools for orchestration, service discovery and load balancing that can be used with Docker and Rocket containers. As needs change, a developer can move container workloads in Kubernetes to another cloud provider without changing the code. 
It helps automates the deployment, scaling, maintenance, scheduling and operation of multiple application containers across clusters of nodes. 

Q: What are the advantages of Kubernetes?
A:
 The advantages of using Kubernetes are as follows-
  • Automated Scheduling- Kubernetes provides advanced scheduler to launch container on cluster nodes. Kubernetes role is to automate the distribution (scheduling) of application containers across a cluster in an efficient way.
  • Auto Healing Capabilities - Kubernetes auto-healing mechanisms, such as auto-restarting, re-scheduling, and replicating containers
  • Automated Rollback - Sometimes you may want to rollback a Deployment; for example, when the Deployment is not stable, such as crash looping. By default, all of the Deployments rollout history is kept in the system so that you can rollback anytime you want.
  • Horizontal Scaling - Autoscaling is one of the key features in Kubernetes cluster. It is a feature in which the cluster is capable of increasing the number of nodes as the demand for service response increases and decrease the number of nodes as the requirement decreases.

Q: What is Docker?
A:
 Consider a scenario - You have just joined a new organization as a developer. You will now have to setup the project with the assistance of a fellow developer. He suggests you follow certain steps for setting up the required environment and then start the project deployable like a WAR. You do the same, but keep getting some or other issues regarding environment configuration. May be even your fellow developer has forgot some configuration property he might have set. Well you are stuck in such a situation. This is known as Dependency Hell. Other similar scenario of this dependency hell are - The application is running on my dev machine but not in production. Dont know what issue is. There is also other scenarios like Matrix of Hell. But this is mostly related to DEVOPS people. Docker to the rescue.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Docker Tutorials 

Q: How to deploy Spring Boot WAR to Docker?
A:
 Deploying Spring Based WAR Application to Docker 

Q: How to deploy Spring Boot JAR to Docker?
A:
 Deploying Spring Based JAR Application to Docker 

Q: How to deploy multiple microservices to Docker?
A:
 Deploying Multiple Spring Boot Microservices using Docker Networking

Q: What are the scenarios in which a Java Developer will use Docker?
A:
Following scenarios a java developer can use docker-
  • Sharing development workspace, with preconfigured development environment.
  • Continuous integration is one of the most popular use cases for Docker. Teams looking build and deploy their applications quickly use Docker, combined with ecosystem tools like Jenkins, to drive apps from dev, testing staging and into production without having to change any code.
  • Running UAT's using Docker

Q: What are namespaces in Kubernetes?
A:
 Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces. Kubernetes allows use of multiple namespaces.

Q: What is a node in Kubernetes?
A:
 A node is a worker machine in Kubernetes, previously known as a minion. A node may be a VM or physical machine, depending on the cluster. Each node has the services necessary to run pods and is managed by the master components. The services on a node include the container runtime, kubelet and kube-proxy. 

Q: What is a pod in Kubernetes?
A:
 A Kubernetes pod is a group of containers that are deployed together on the same host. If you frequently deploy single containers, you can generally replace the word "pod" with "container" and accurately understand the concept.