What are Namespaces and Services in Kubernetes?
In Kubernetes, Namespaces are used to create isolated environments for resources. Each Namespace is like a separate cluster within the same physical cluster.
Services are used to expose your Pods and Deployments to the network.
Task 1:Create a Namespace for your Deployment
Use the below command to create a Namespace
kubectl create namespace <namespace-name>
- Update the deployment.yml file to include the Namespace
Apply the updated deployment using the command:
kubectl apply -f deployment.yml -n <namespace-name>
Here's a breakdown of the command:
kubectl apply: This is the primary command for applying or updating Kubernetes resources.
-f deployment.yml: This flag specifies the path to the YAML or JSON file containing the configuration for the Kubernetes resource you want to create or update. In this case, it's a file named deployment.yml.
-n <namespace-name>: This flag specifies the namespace in which the resources should be created or updated.
Putting it all together, the command
kubectl apply -f deployment.yml -n <namespace-name>
is saying: "Apply the configuration specified in the deployment.yml file to the Kubernetes cluster, and do it in the namespace named <namespace-name>."
This command is commonly used when you want to deploy or update resources within a specific namespace in a Kubernetes cluster. It ensures that the resources are created or updated in the specified namespace rather than the default namespace.
- Verify that the Namespace has been created by checking the status of the Namespaces in your cluster.
Task 2:Read about Services, Load Balancing, and Networking in Kubernetes
Services
A Kubernetes Service is an abstraction that outlines a collection of Pods and establishes a policy for interacting with them. It provides a consistent endpoint, comprising an IP address and port, facilitating communication with a cluster of replicated Pods.
Load Balancing
Load balancing guarantees the equal distribution of traffic among numerous Pods, enhancing application availability and reliability.
Networking
Networking enables seamless communication between containers, pods, and services within the cluster. It encompasses various components and mechanisms facilitating efficient data exchange and traffic management.
Thanks for reading!