Ace Your Kubernetes Interview-II

Saurabh Dahibhate ♾️☁️
6 min readApr 14, 2023

--

Day 37 Task: Top 16 Kubernetes Interview Questions and Answers Part-II

Hello everyone I am back with another task of DevOps😊.

Top-16-Kubernetes-Interview-Questions-and-Answers-Part-II

This is Part 02 Interview questions of Kubernetes.

Note: All answers are in descriptive manner if you want short answers then the PDF of short answers is given in Part 03

So let’s Start…

06. Can you explain the concept of rolling updates in Kubernetes?

In Kubernetes, rolling updates is a deployment strategy that allows updating a running application without downtime or disruption to end users. It works by creating a new replica set with the updated version of the application and gradually scaling it up while scaling down the old replica set. This way, the traffic is gradually shifted to the new version until all the pods in the old replica set are terminated.

Rolling updates can be configured in several ways, including the number of replicas to be updated at a time, the interval between updates, and the maximum number of pods that can be unavailable during the update. This approach ensures that the application is always available to the users, and any issues with the new version can be detected and resolved before it affects the entire deployment.

Example:

let’s say you have a deployment with four replicas running version 1.0 of your application. You want to update the application to version 2.0 without any downtime. You can create a new replica set with version 2.0 and gradually scale it up while scaling down the old replica set. This way, users will still be able to access the application while the update is taking place. Once all the pods in the old replica set are terminated, the new version is fully deployed.

07. How does Kubernetes handle network security and access control?

Kubernetes provides various features to handle network security and access control. Some of the key features are:

  1. Network Policies: Kubernetes supports Network Policies that allow you to define how pods are allowed to communicate with each other and other network endpoints. With network policies, you can restrict access between pods or namespaces to create a more secure environment.
  2. Service Accounts: Kubernetes provides Service Accounts that enable you to control access to the Kubernetes API server and other resources in the cluster. You can assign specific roles and permissions to Service Accounts to restrict or grant access to resources.
  3. Role-Based Access Control (RBAC): Kubernetes supports RBAC, which allows you to define roles and permissions for users and Service Accounts. RBAC allows you to create fine-grained access control policies for different resources in the cluster.
  4. Secrets: Kubernetes provides Secrets, which allow you to store and manage sensitive information like passwords, keys, and tokens securely. You can use Secrets to control access to sensitive data in your applications.

Overall, Kubernetes provides various tools and features to help you secure your network and control access to your cluster resources. By using these features effectively, you can create a more secure and reliable Kubernetes environment.

08. Can you give an example of how Kubernetes can be used to deploy a highly available application?

Here’s an example of how Kubernetes can be used to deploy a highly available web application:

  1. First, create a Docker image of your web application and push it to a container registry like Docker Hub.
  2. Create a Kubernetes Deployment object that defines the desired state of your application, including the number of replicas, the container image to use, and any environment variables or other configuration.
  3. Create a Kubernetes Service object that provides a stable, load-balanced IP address for your application. This ensures that traffic is distributed evenly across all replicas of your application.
  4. Set up a Kubernetes Ingress object to expose your application to the internet. This allows external traffic to access your application through a single entry point, while also providing SSL termination, load balancing, and other advanced features.
  5. Configure Kubernetes to automatically scale your application up or down based on resource utilization, using Horizontal Pod Autoscaling (HPA). This ensures that your application can handle sudden spikes in traffic without going down.
  6. Use Kubernetes rolling updates to deploy new versions of your application without any downtime. This ensures that your users always have access to the latest features and bug fixes, while also minimizing the risk of service disruption.

By following these steps, you can deploy a highly available web application on Kubernetes that can handle large amounts of traffic, scale dynamically, and update seamlessly.

09. What is namespace is kubernetes? Which namespace any pod takes if we don’t specify any namespace?

In Kubernetes, a namespace is a way to logically isolate resources within a cluster. It provides a scope for naming resources and helps in preventing naming collisions. By default, if a namespace is not specified, the pod is created in the “default” namespace.

Example:

If you have two teams within an organization, each team can have its own namespace to work within. This allows for better organization of resources and easier management of access control.

Let’s say you have two teams, Team A and Team B. You can create two namespaces, “team-a” and “team-b”, respectively. The resources created by each team can be segregated within their respective namespaces. If a pod is created without specifying a namespace, it will be created in the “default” namespace.

10. How ingress helps in kubernetes?

In Kubernetes, Ingress is an API object that provides a way to manage external access to the services in a cluster. In other words, it acts as a layer between the public network and the services running inside the Kubernetes cluster, enabling external traffic to be routed to the appropriate service based on the requested URL.

With Ingress, you can define rules that specify how incoming traffic should be directed to different services, based on factors such as URL paths or hostnames. This allows for more fine-grained control over traffic routing and enables features like load balancing, SSL termination, and more.

Example:

Let’s say you have multiple microservices running in your Kubernetes cluster, and you want to expose them to the internet using a single IP address and port. You can create an Ingress object that maps each service to a unique hostname and path. Then, you can configure a load balancer or a DNS provider to point to the IP address of your Ingress controller, and traffic will be automatically routed to the correct service based on the request’s hostname and path.

Here’s an example YAML definition of an Ingress resource that routes traffic to two different services based on the path:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /service-a
pathType: Prefix
backend:
service:
name: service-a
port:
name: http
- path: /service-b
pathType: Prefix
backend:
service:
name: service-b
port:
name: http

In this example, the Ingress object routes traffic to two different services (service-a and service-b) based on the request's path. The nginx.ingress.kubernetes.io/rewrite-target annotation rewrites the request's path before sending it to the backend service, so that both services can handle the request as if it was sent to the root path (/).

Click Here for Part 01 Interview questions of Kubernetes.

Click Here for Part 03 Interview questions of Kubernetes.

🔶That’s all about today’s task of DevOps journey.

🔸Thankyou for reading 👍.

If you liked this story then click on 👏👏 do follow for more interesting and helpful stories.

— — — — — — — #keepLearning_DevOpsCloud ♾️☁️ — — — — — —

Ace-Your-Kubernetes-Interview-II

--

--

Saurabh Dahibhate ♾️☁️

- ⭐Passionate Web Developer and DevOps . 🎯 Like to stay up-to-date with the latest trends and insights.