Logo

dev-resources.site

for different kinds of informations.

ClusterIP vs. NodePort

Published at
1/4/2025
Categories
clusterip
nodeport
kubernetes
cka
Author
cheedge_lee
Categories
4 categories in total
clusterip
open
nodeport
open
kubernetes
open
cka
open
Author
11 person written this
cheedge_lee
open
ClusterIP vs. NodePort

ClusterIP

kubectl expose deployment nginx --name nginx-svc --port 8080 --target-port 80
Enter fullscreen mode Exit fullscreen mode

NodePort

kubectl expose deployment nginx --name nginx-svc --port 8081 --target-port 80 --type NodePort
Enter fullscreen mode Exit fullscreen mode

Different Ports

  1. target-port -- container port
    • Where your pod/container listens
    • k get endpoints
  2. port -- service's internal port
    • access the svc from other port
    • k get svc
  3. NodePort -- expose to external/all nodes
    • k get endpoints or k get svc
controlplane $ k get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
apache-svc   ClusterIP   10.104.249.75   <none>        8080/TCP         2m11s
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP          2d8h
nginx-svc    NodePort    10.97.210.100   <none>        8081:32433/TCP   3s
controlplane $ k get node -owide
NAME           STATUS   ROLES           AGE    VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
controlplane   Ready    control-plane   2d8h   v1.31.0   172.30.1.2    <none>        Ubuntu 20.04.5 LTS   5.4.0-131-generic   containerd://1.7.13
Enter fullscreen mode Exit fullscreen mode

ClusterIP vs. NodeIP

  • For accessing from nodes:
    • curl localhost:NodePort or curl NODE_IP:NodePort (NodePort)
    • curl SVC_IP:SVC_Port (ClusterIP)
# SVC_IP:SVC_Port
controlplane $ curl 10.97.210.100:8081
# Node_IP:Node_Port
controlplane $ curl 172.30.1.2:32433
# localhost:NodePort
controlplane $ curl localhost:32433
Enter fullscreen mode Exit fullscreen mode
  • For accessing from inside another pod:
    • curl SVC_NAME:SVC_Port or curl SVC_IP:SVC_Port
# SVC_NAME:SVC_Port
~ # curl nginx-svc:8081
~ # curl apache-svc:8080
# SVC_IP:SVC_Port
~ # curl 10.104.249.75:8080
~ # curl 10.97.210.100:8081
Enter fullscreen mode Exit fullscreen mode

Endpoints

The Endpoints object (192.168.0.7:80) shows the actual pod IP and port where the traffic will eventually go. It's the backend configuration that tells Kubernetes where to forward the traffic from the service.
Therefore, endpoints IP -> Pod IP

controlplane $ k get endpoints
NAME         ENDPOINTS         AGE
apache-svc   192.168.0.6:80    2m20s
kubernetes   172.30.1.2:6443   2d8h
nginx-svc    192.168.0.7:80    12s
Enter fullscreen mode Exit fullscreen mode
cka Article's
30 articles in total
Favicon
Turning Markdown into Learning: publishing a challenge on labs.iximiuz.com
Favicon
CKA Quick Check Points -- RBAC
Favicon
CKA Quick Check Points -- Network
Favicon
CKA Quick Check Points -- Logs & Configs
Favicon
CKA Recap -- Deployment
Favicon
ClusterIP vs. NodePort
Favicon
CKA Recap -- Ingress & NetworkPolicy
Favicon
Kubernets Storage Demos
Favicon
3. CKA Storage
Favicon
Why must a Kubernetes cluster have an odd number of nodes
Favicon
Understanding Pod Topology Spread Constraints in Kubernetes
Favicon
Deployments and Replica Sets in Kubernetes
Favicon
40 days of Kubernetes: Docker Fundamentals
Favicon
Understanding Kubernetes Pods and YAML Fundamentals
Favicon
Creating a Kubernetes Cluster with Kubeadm and Containerd: A Comprehensive Step-by-Step Guide
Favicon
Mastering Multi-Stage Builds in Docker 🚀
Favicon
Mastering Docker Fundamentals: The First Step in Becoming a Certified Kubernetes Administrator
Favicon
How I Passed the Certified Kubernetes Administrator (CKA) Exam and How You Can Too
Favicon
AWS EKS Ingress - Canary
Favicon
Certified Kubernetes Administrator (CKA) Prep.
Favicon
Certified Kubernetes Administrator (CKA) - Several Successful Story
Favicon
YouTube 13k Subscriber crossed! Exciting Giveaway
Favicon
How to Pass the Certified Kubernetes Administrator Examination
Favicon
'Kubernetes Complete Course In 10 Hours' – your ultimate beginner's guide to Kubernetes FREE!
Favicon
Kubernetes CKA Exam Question Bank .. 17 Questions with Complete Lab .. In 3 hours .. FREE!
Favicon
ROAD TO CKA [Certified Kubernetes Administrator ]-Core Concept- Pod(Day-7)
Favicon
ROAD TO CKA [Certified Kubernetes Administrator ]-Kubernetes Architecture(Day-4)
Favicon
Installing Kubernetes-1.27.0 in Ubuntu 22.04
Favicon
ROAD TO CKA [Certified Kubernetes Administrator ]-What Kubernetes is & is not?(Day-3)
Favicon
ROAD TO CKA [Certified Kubernetes Administrator ]-Core Concept- Control Plane/Master Node (Day-5)

Featured ones: