You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kubectl run nginx --image=nginx
kubectl run apache --image=httpd
kubectl get pod -o wide
kubectl exec --it nginx -- sh
curl <Apache_POD_IP>## exit pod
kubectl logs apache
# You should see the IP of the nginx pod IP making requests. This is because pods in the same cluster (if no network pols are defined) can communicate by default
DNS & Service discovery
graph TD
subgraph Kubernetes Cluster
A[Client Pod]
B[Website Deployment]
C[DNS Server - 10.1.0.10]
A -->|wget website| SVC[Website Service]
A -->|wget website.default| C
A -->|wget website.default.svc.cluster.local| C
A -->|nslookup website.default.svc.cluster.local| C
C -->|response with IP| A
B -->|Exposes on port 80| SVC
end
subgraph DNS Resolution
R[resolv.conf]
R -->|search domain| DNS[default.svc.cluster.local]
DNS -->|Nameserver IP| C
end
Note1[Note: DNS server IP 10.1.0.10 resolves service names to IP addresses]
Note2[Note: resolv.conf contains DNS search domains and nameserver]
Note1 --> Kubernetes_Cluster
Note2 --> DNS_Resolution
Loading
kubectl create deployment website --replicas=1 --image=httpd
kubectl expose deployment website --port=80
kubectl run -it client --image busybox
wget -qO - website ## (use capital o "O", not zero/0)
wget -qO - website.default
wget -qO - website.default.svc.cluster.local
cat /etc/resolv.conf
###
search default.svc.cluster.local svc.cluster.local cluster.local ok4igb2s51uerbsb5uc1zxhnfb.zx.internal.cloudapp.net
nameserver 10.1.0.10
options ndots:5
## nameservers 10.1.0.10 is the IP of the default K8s service called "kubernetes" when you do `kubectl get svc`## It's our cluster DNS service. Services give dynamic sets of pods a stable "head" identity.## nslookup & dig
/ # nslookup echo-server.default.svc.cluster.local
Server: 10.1.0.10
Address: 10.1.0.10:53
Name: echo-server.default.svc.cluster.local
Address: 10.1.135.254
/ # nslookup website.default.svc.cluster.local
Server: 10.1.0.10
Address: 10.1.0.10:53
Name: website.default.svc.cluster.local
Address: 10.1.180.30
Headless labs
## Ignoring the failed lookups, you can see that looking up a headless service by name actually returns the IP addresses of the endpoints.## You can also retrieve the SRV record for the service:
nslookup -q=SRV headlesswebsite
DNS Lookups in Services
Kubernetes uses a DNS server to provide service discovery for pods
kubectl run web --image=httpd
kubectl get pod -o wide
## Test pod net
kubectl run client -it --image=busybox
ip a
ping -c 3 <WEB POD IP>
wget -qO - <WEB POD IP>
Ingress resources manage external access to services, typically HTTP.
Examples of ingress controller include: NGINX, Traefik, HAProxy and more.
For ingress in K8s to work, you need to create ingress controllers and then you can setup an ingress to a certain service. Ingress controllers will generally spin up load balancer type of services in your cloud provider where the cluster lives.
Service mesh
Service mesh provides additional features like traffic management, security, and observability.