What is a Namespace?
You can think of a Namespace as a virtual cluster inside your Kubernetes cluster. You can have multiple namespaces inside a single Kubernetes cluster, and they are all logically isolated from each other. They can help you and your teams with organization, security, and even performance!
The functionality of Namespace:-
Following are some of the important functionalities of a Namespace in Kubernetes −
Namespaces help pod-to-pod communication using the same namespace.
Namespaces are virtual clusters that can sit on top of the same physical cluster.
They provide logical separation between the teams and their environments.
Task 1:-
Create a Namespace for your Deployment
Use the command
kubectl create namespace <namespace-name>
to create a Namespace
kubectl create namespace my-app
kubectl get namespace
- Update the pod.yml file to include the Namespace
- Apply the updated deployment using the command:
kubectl apply -f pod.yml
- Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.
kubectl get pods -n=<name_of_namespace>
# Ex:- kubectl get pods -n=my-app
Task 2:- Explain Services, Load Balancing, and Networking in Kubernetes
Service
A service is a functionality that is by default disabled on the containers, pods, and nodes. We need to mention about specific service that we want to enable. Some of the services offered by the Kubernetes cluster are NodePort and Load Balancer services. We have discussed in detail the load balancer service below in the article.
What are the types of Kubernetes services?
ClusterIP. Exposes a service that is only accessible from within the cluster.
NodePort. Exposes a service via a static port on each node’s IP.
LoadBalancer. Exposes the service via the cloud provider’s load balancer.
ExternalName. Maps a service to a predefined external name field by returning a value for the CNAME record.
Load Balancer
Suppose we run a company and we want to hire some employees. We have shared a link on which interested candidates can share their resumes and book a slot for the interview. But our website can only handle about 10 people at a time. This can lead to the loss of great talent and eventually, this is a loss to the company. To solve this problem we needed load balancers. these load balancer launches a new clone website when the number of users reaches a certain limit and redirect those extra users to the newly created clone website.
To create a load balancer service we have to create a service manifest file and to link this service to the pods we can use the labels of the pods previously used in the deployment manifest file.
#Service
apiVersion: v1
kind: Service
metadata:
name: service-nginx
labels:
app: nginx-application
spec:
selector:
app: nginx-application
type: LoadBalancer
ports:
- nodePort: 31000
port: 80
targetPort: 80
Networking
Networking in any architecture or technology is very essential to understand if you want to deploy the applications over the network and also understanding how the network works will help you to troubleshoot if you have any network issues. So we must know exactly what is happening in the network and how all the connections are established for communication over the network.
This is a basic Kubernetes architecture where you have some worker nodes and a few pods running on it with a couple of containers. When you have these many components, how do all these components are establishing their connection to make the application accessible over the network? The answer is that happens only through Kubernetes networking.
3 things we need to remember:-
All the NODES in the K8s cluster should talk to each other
All the PODS in K8s cluster should communicate with each other without NAT
Every POD its Ip address