DNS in k8s
- Kubernetes comes with DNS implementation by using CoreDNS
- Kubernetes DNS runs as regular service that is scheduled on the cluster.
- This configures kubelet running on each node so that containers use the DNS service IP’s to resolve DNS Name.
- The service exists with name
Activity: Create a k8s service with 3 nginx pods in deployment
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
- Service yaml
--- apiVersion: v1 kind: Service metadata: name: nginx-svc spec: selector: app: nginx ports: - name: nginx-svc protocol: TCP port: 80
- get endoints
- Get Endpoint slices
- Endpoints help identify what pods are running for the service, Endpoints are created and managed by services
- Now lets describe endpoint
apiVersion: v1 kind: Endpoints metadata: name: nginx-svc subsets: - addresses: - ip: 192.168.0.8 nodeName: controlplane targetRef: kind: Pod name: nginx-deployment-cbdccf466-6q5f9 namespace: default uid: 9e2da211-7213-40de-921f-7e871690fcac - ip: 192.168.1.3 nodeName: node01 targetRef: kind: Pod name: nginx-deployment-cbdccf466-kxc47 namespace: default uid: 69ea9d52-94fa-4bb9-8650-cddefeb947e8 ports: - name: nginx-svc port: 80 protocol: TCP
Services in K8s
- A Service in k8s is a load balancing abstraction within a cluster.
- There are four types of services
- expose the nginx service using type NodePort (kubeadm)
Internet/External to Service Networking
Here we have two perspectives
- Routing traffic from Pod to Internet (Egress)
- Routing traffic to Kubernetes (Ingress)
- Layer 4: Load Balancer
- Layer 7: Ingress Controller