section-5-main

Mastering K8 Commands: Section 5

  |  

0 Comments Kubernetes Networking Services

Services and Networking in Kubernetes

Kubernetes services and networking are pivotal for ensuring that applications are accessible and can communicate effectively within the cluster. This section delves into kubectl commands that are essential for managing services and networking in Kubernetes, offering insights into service exposure, load balancing, and network policies.

Creating and Managing Services

Services in Kubernetes are an abstract way to expose an application running on a set of Pods as a network service.

Create a Service:

kubectl expose deployment nginx-deployment --type=LoadBalancer --name=my-service
  • What It Does: Exposes the nginx-deployment as a service named my-service using a LoadBalancer.
  • Context: LoadBalancer type makes the service accessible externally. It’s ideal for production environments where external access to services is required.

Listing and Inspecting Services

To manage and troubleshoot services, understanding how to list and describe them is key.

List Services:

kubectl get services
  • What It Does: Shows all the services in the current namespace.

Describe a Service:

kubectl describe service my-service
  • What It Does: Provides detailed information about the service, including endpoints, associated pods, and ports.

Port Forwarding

Port forwarding is a useful technique for debugging and development purposes.

Port Forwarding:

kubectl port-forward service/my-service 8080:80
  • What It Does: Forwards traffic from your local machine’s port 8080 to the service’s port 80.
  • Use Case: Ideal for local testing and debugging of services running in the Kubernetes cluster.

Previous: ← Section 4: Managing Deployments
Next: Section 6: Configurations and Secrets →