Git
Git
Answer: Git is a distributed version control system that allows multiple developers to collaborate on
a project. It differs from other systems by its distributed nature, speed, and ability to handle
branching and merging efficiently.
Answer: The basic Git workflow involves three main stages: working directory, staging area, and
repository. Changes are made in the working directory, staged using git add to move them to the
staging area, and then committed to the repository using git commit.
Answer: A repository in Git is a storage location for a project, containing the project's files, version
history, and configuration data. It can be local (on a developer's machine) or remote (on a server,
e.g., GitHub).
Answer: The staging area allows developers to selectively choose which changes to include in the
next commit. It acts as a middle ground where modifications are prepared before being committed.
Answer: git pull fetches changes from a remote repository and merges them into the current branch.
git fetch only retrieves changes from the remote but doesn't automatically merge them. It allows you
to review changes before merging.
Answer: Branching in Git allows developers to create separate lines of development. Each branch
represents a different set of changes, and they can be merged back together later.
Answer: A merge conflict occurs when Git cannot automatically merge changes from different
branches. It requires manual intervention to resolve conflicts by editing the conflicting files, marking
them as resolved, and then committing the changes.
Answer: Git tracks changes to binary files by storing each version separately. This can lead to larger
repository sizes for binary files, and it may not handle them as efficiently as text files.
9. What is the purpose of the .gitignore file?
Answer: The .gitignore file specifies intentionally untracked files that Git should ignore. It's used to
prevent irrelevant files (like build artifacts, logs, and temporary files) from being accidentally
committed.
Answer: Git is a version control system, while GitHub is a web-based platform that provides hosting
for Git repositories. GitHub enhances collaboration by providing features like pull requests, issue
tracking, and project management tools.
11. What is a pull request in GitHub, and how does it facilitate collaboration?
Answer: A pull request is a GitHub feature that allows developers to propose changes to a repository.
It facilitates collaboration by providing a space for discussion, reviewing code changes, and
integrating the proposed modifications into the main branch.
12. How do you revert a commit that has already been pushed and shared with others?
Answer: Use git revert to create a new commit that undoes the changes introduced by a previous
commit. This allows you to maintain a clean history without rewriting the commit history.
13. What is Git cherry-pick, and when would you use it?
Answer: Git cherry-pick is used to apply a specific commit from one branch to another. It is useful
when you want to pick specific changes from one branch and apply them to another.
14. Explain the Git rebase command and when it might be used.
Answer: Git rebase is used to move or combine a sequence of commits to a new base commit. It is
often used to maintain a clean and linear commit history by incorporating changes from one branch
into another.
Answer: Use git reset HEAD~1 to undo the last commit while keeping the changes in the working
directory. If the changes should be discarded, use git reset --hard HEAD~1.
Answer: Git hooks are scripts that can be executed at key points in the Git workflow, such as pre-
commit or post-merge. They allow developers to automate tasks or enforce custom workflows.
18. How do you squash multiple commits into a single commit in Git?
Answer: Use git rebase -i HEAD~n (where n is the number of commits to squash). In the interactive
rebase, mark commits as "squash" to combine them into a single commit.
Answer: Git submodules allow you to include other Git repositories within your own repository. They
are useful for managing dependencies or including external projects as part of your larger project.
20. How would you handle a situation where you accidentally push sensitive information (like
passwords) to a Git repository?
Answer: Immediately remove the sensitive information from the code. Then use git filter-branch or
git filter-repo to remove the sensitive data from the entire commit history. Finally, force-push the
corrected history to the remote repository, and communicate the issue to other collaborators.
1. What is Docker?
Docker is an open-source platform that allows you to automate the deployment, scaling, and
management of applications using containerization.
2. What is a container?
A container is a lightweight and isolated environment that encapsulates an application and its
dependencies, allowing it to run consistently across different environments.
Virtualization emulates an entire operating system, while Docker containers share the host system's
kernel and only isolate the application processes.
You can create a Docker image using a Dockerfile, which is a text file that contains a set of
instructions for building the image.
6. What is a Dockerfile?
A Dockerfile is a text file that contains instructions for building a Docker image. It specifies the base
image, application code, dependencies, and other configurations.
Docker Compose is a tool that allows you to define and manage multi-container Docker applications.
It uses a YAML file to configure the application's services and their dependencies.
In Docker, you can link containers using the --link flag or by creating a user-defined network and
connecting containers to the network.
Docker Swarm is a native clustering and orchestration solution provided by Docker. It allows you to
create and manage a cluster of Docker nodes to deploy and scale applications.
Docker Swarm is a simpler and less feature-rich orchestration tool compared to Kubernetes. It is
suitable for small to medium-sized deployments, while Kubernetes is more scalable and suitable for
complex, large-scale deployments.
You can scale Docker containers manually by running multiple instances of the same container or use
orchestration tools like Docker Swarm or Kubernetes to automatically scale the containers based on
predefined rules.
An image is a template used to create containers. Containers are running instances of images that
have their own filesystem and can be started, stopped, and managed.
You can share Docker images with others by pushing them to a Docker registry, such as Docker Hub
or a private registry. Others can then pull the image from the registry to use it.
Data persistence in Docker can be achieved by using Docker volumes or mounting host directories
into containers. Docker volumes provide a way to manage and share data between containers and
also persist data even if the containers are removed.
The ENTRYPOINT instruction specifies the command that will be executed when the container starts.
The CMD instruction provides default arguments to the entry point command.
You can access logs from a Docker container using the docker logs command followed by the
container ID or name.
You can pass environment variables to a Docker container using the -e flag followed by the variable
name and value when running the docker run command.
19. What is the difference between a Docker image and a Docker container?
A Docker image is a static, read-only file that contains the application and its dependencies, while a
Docker container is a running instance of an image that has its own state and can be started,
stopped, and managed.
Docker Registry is a service that stores and distributes Docker images. Docker Hub is the default
public Docker Registry, but you can also set up your own private registry.
To update a Docker image, you need to rebuild it with the necessary changes and then push the
updated image to the Docker registry. Existing containers can be stopped and recreated with the new
image.
Docker volumes are a way to persist data generated by and used by Docker containers. They provide
a mechanism for managing and sharing data between containers, as well as persisting data even if
the containers are removed.
You can list Docker containers using the docker ps command. The -a flag can be used to display all
containers, including the ones that are not currently running.
Docker networks provide a way to enable communication between containers running on the same
host or across different hosts. They allow containers to discover and connect to each other using
container names.
To update a Docker container, you need to stop the existing container, pull the updated image from
the Docker registry, and then start a new container with the updated image.
27. What is the difference between COPY and ADD instructions in a Dockerfile?
The COPY instruction in a Dockerfile copies files and directories from the build context to the image.
The ADD instruction can do the same but also supports additional features like extracting tar archives
and downloading files from URLs.
28. What is the role of a Dockerfile's EXPOSE instruction?
The EXPOSE instruction in a Dockerfile informs Docker that the container listens on the specified
network ports at runtime. It does not actually publish the ports to the host, but it is useful for
documentation purposes and when creating container links.
Docker is a containerization platform that allows you to create, package, and run applications in
containers. Kubernetes, on the other hand, is a container orchestration platform that automates the
deployment, scaling, and management of containerized applications.
You can clean up unused Docker resources using the docker system prune command. This command
removes unused images, containers, volumes, and networks, freeing up disk space. Use it with
caution, as it permanently deletes resources.
Answer:
· Master Node:
Ø API Server: Acts as the central control point for managing the cluster, receiving commands through
the Kubernetes API.
Ø etcd: A distributed key-value store that stores configuration data, serving as the cluster's "brain."
Ø Controller Manager: Maintains desired state of the cluster by regulating various controllers (e.g.,
node, replica, endpoints).
Ø Scheduler: Assigns work (containers) to nodes based on resource availability and constraints.
· Node:
Ø Kubelet: Ensures containers are running in a Pod (smallest deployable unit) by interacting with the
API Server and managing containers.
Ø Kube Proxy: Maintains network rules to route traffic to appropriate containers within Pods.
Ø Container Runtime: Executes containers (e.g., Docker, containerd) and manages their lifecycle.
· Pod:
Ø Smallest deployable unit in Kubernetes, encapsulating one or more containers that share
networking and storage.
Ø Containers within a Pod share the same IP address and port space, allowing easy communication.
Ø Pods can be scheduled and scaled as a unit.
· Controller:
Ø Controllers ensure the desired state of the system and respond to changes to maintain that state.
Ø ReplicaSet: Ensures a specified number of replicas of a Pod are running at all times.
Ø StatefulSet: Manages stateful applications requiring stable network identities and ordered
deployment.
· Service:
Ø Allows data to persist across container restarts and be shared among containers in a Pod.
· Namespace:
Ø Virtual clusters within a physical cluster, allowing resource segregation and access control.
Answer: A Pod is the smallest deployable unit in Kubernetes, representing a single instance of a
running process in the cluster. It is the smallest unit because it can contain one or more containers
that share the same network namespace and storage, making them tightly coupled for co-located
services or dependencies.
4. How do you scale applications in Kubernetes? What are Horizontal and Vertical Pod
Autoscalers?
Answer: Applications in Kubernetes can be scaled using Horizontal Pod Autoscalers (HPA) and Vertical
Pod Autoscalers (VPA).
HPA: Automatically adjusts the number of Pods based on CPU or custom metrics, ensuring optimal
resource utilization.
VPA: Adjusts the CPU and memory resources allocated to Pods based on their actual resource usage,
ensuring efficient utilization.
Answer:
Deployment: Used for stateless applications, provides easy scaling, updates, and rollbacks.
StatefulSet: Used for stateful applications that require stable network identities and persistent
storage. Ensures ordered deployment and scaling.
6. What is a Service in Kubernetes, and why is it needed?
Answer: A Service in Kubernetes is an abstraction that exposes a set of Pods as a network service. It
is needed to provide a stable and network-accessible endpoint to access Pods, load balance traffic,
and enable communication between different parts of an application.
7. How does Kubernetes manage container networking, and what is a Pod Network?
Answer: Kubernetes uses a Container Network Interface (CNI) to manage container networking. A
Pod Network is a flat, overlay network that allows Pods to communicate with each other regardless
of their physical or virtual host, making it easier to manage container networking in a cluster.
8. What are Ingress controllers in Kubernetes, and why are they used?
Answer: Ingress controllers are used to manage external access to services within a cluster. They
provide HTTP and HTTPS routing, load balancing, and SSL termination. Examples include Nginx
Ingress Controller and Traefik.
Answer: Kubernetes manages storage using Persistent Volumes (PVs) and Persistent Volume Claims
(PVCs). PVs are physical storage resources, and PVCs are requests for storage. Kubernetes ensures
that the correct PV is bound to a PVC and then mounted to a Pod, providing persistent storage.
10. What is a ConfigMap and a Secret in Kubernetes? How are they used?
Answer: ConfigMaps store configuration data, and Secrets store sensitive information like passwords
and API keys. They are used to decouple configuration from Pods, making it easier to manage
configuration changes and secrets without modifying the application code or container images.
Answer: Kubernetes handles updates and rollbacks by managing Deployments. You can update a
Deployment by changing its container image, and Kubernetes will perform rolling updates by
gradually replacing old Pods with new ones. Rollbacks can be triggered if issues arise during the
update.
Answer: A DaemonSet ensures that a specific Pod runs on all or selected Nodes in the cluster. It is
used for tasks that should run on every Node, such as logging agents or monitoring tools.
13. Describe Kubernetes' role in handling application health checks and self-healing.
Answer: Kubernetes continuously monitors Pods and can automatically restart or replace Pods that
are unhealthy based on liveness and readiness probes. This self-healing capability ensures that
applications remain available and reliable.
15. How can you manage secrets and sensitive information securely in Kubernetes?
Answer: Secrets can be managed securely in Kubernetes using Kubernetes Secrets or external secret
management tools. Secrets are stored encrypted in etcd, and access control can be applied to restrict
who can access them.
16. Explain the difference between a Rolling Update and a Blue-Green Deployment in Kubernetes.
Answer:
Rolling Update: Gradually replaces old Pods with new ones, ensuring zero downtime and minimal
resource impact.
Blue-Green Deployment: Deploys a new version of an application alongside the old one, allowing for
quick switching between versions by updating a load balancer.
17. What is Helm, and how does it simplify the deployment of applications in Kubernetes?
Answer: Helm is a package manager for Kubernetes that simplifies application deployment and
management by providing pre-configured packages (Charts) with customizable values. It streamlines
the process of deploying complex applications and ensures consistency.
18. How can you monitor and log Kubernetes clusters effectively?
Answer: Effective monitoring and logging in Kubernetes can be achieved using tools like Prometheus
for monitoring and Grafana for visualization. For logging, solutions like Elasticsearch, Fluentd, and
Kibana (EFK stack) or Loki and Grafana (Grafana Loki) can be used to collect, store, and query logs.
19. What are the main differences between Kubernetes and Docker Swarm for container
orchestration?
Answer:
Kubernetes is more feature-rich, suitable for complex deployments, and has a larger community.
Docker Swarm is simpler to set up and use, better for smaller projects, and tightly integrated with
Docker.
20. Describe the process of deploying a multi-container application with Kubernetes, including
defining the necessary YAML files.
Answer: The process involves creating Pods, Services, Deployments, and other resources in YAML
files, defining container specifications, networking, and scaling requirements. YAML files are then
applied to the cluster using kubectl apply -f.