Label Selectors
- Refer Here for official docs
- Equality based selector
- Set based selector
Controllers in k8s
- Controllers in k8s indirectly create pods
- Controllers:
- Replicaset: Scaling Pods
- Desired State: Number of pods
- ReplicationController:
- Desired State: Number of pods
- Deployment
- Desired State: Number of pods via Replicasets to deploy apps with zero downtime
- Job
- Desired State: Run the Pod to Completion
- CronJobs
- Desired State: Run the Pod to Completion on Schedule
- Statefulset: TBD
- Daemonset: TBD
- Replicaset: Scaling Pods
- When we are dealing with Controllers we will have some extra elements to consider
- template: This generally refers to pod specification
- matching labels and selectors
- Overview of Deployment

Replicaset
- official docs
- Lets write a replicaset which creates 3 nginx Pods
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
labels:
app: nginx
env: dev
spec:
minReadySeconds: 5
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
version: v1
env: dev
spec:
containers:
- name: web
image: nginx
- Refer Here for changes
- Kuberenetes replicaset will ensure there are desired number of pods with matching labels.
- Even if the exising pods have matching labels it doesnot try to create more that replicas
- Watch classroom video for further commands
- Note: When using Replication Controller while writing label selectors you can do only equality based selection
- Find out how to write a set based expression for matching labels in k8s manifests for replicaset and write a replicaset yaml for httpd with 5 replicas. Refer Here for changes
Accessing applications in k8s
- Each Pod gets an IP Address, Pods get scaled an replaced, directly accesing pods by ip might not be a good idea
- K8s has a component running for service discovery with DNS functionality mostly coredns
- In linux machines we have
/etc/resolve.confwhats the purpose of that?
The /etc/resolv.conf file is a plain-text configuration file that specifies how the Domain Name System (DNS) resolver operates on a system[1]. It contains information that allows applications to translate human-friendly domain names into the numerical IP addresses needed to access resources on a network or the internet[1]. This translation process is known as address resolution[1]. The file is typically located in the /etc directory[1].
The resolv.conf file is used to configure hostname resolution and is commonly used to manage DNS requests on Linux systems[2]. It can be manually configured by a system administrator or automatically populated by network configuration and management tools[2].
Key purposes and functions:
* Nameserver specification The nameserver directive specifies the IP addresses of domain name servers that the resolver can query[1][5]. Multiple nameserver lines can be specified, but each line should only have one IP address, up to a maximum of three[2][5]. The resolver queries the DNS servers in the order listed[2]. If no nameserver entries are present, it defaults to 127.0.0.1[2].
* Search domains The search directive specifies default search domains that are used to complete a given query name to a fully qualified domain name when no domain suffix is supplied[1]. For example, search example.com local.test configures the resolver to try somehost.example.com and somehost.local.test[1].
* Lookup order The /etc/nsswitch.conf file specifies the lookup order for hostnames, determining whether the system consults DNS or the /etc/hosts file first[3].
In systemd-based Linux distributions, /etc/resolv.conf is often a symbolic link to /run/systemd/resolve/stub-resolv.conf[1]. The resolvconf program on FreeBSD and other Unix systems manages the resolv.conf file[1]. On Debian systems, both openresolv and resolvconf can be used to control the alteration of /etc/resolv.conf by networking programs[4].
Citations:
[1] https://en.wikipedia.org/wiki/Resolv.conf
[2] https://wiki.gentoo.org/wiki/Resolv.conf
[3] https://serverfault.com/questions/118923/difference-between-etc-hosts-and-etc-resolv-conf
[4] https://wiki.debian.org/resolv.conf
[5] https://www.baeldung.com/linux/etc-resolv-conf-file
[6] https://superuser.com/questions/570082/in-etc-resolv-conf-what-exactly-does-the-search-configuration-option-do
[7] https://www.youtube.com/watch?v=hflrZcYzcbE
[8] https://docs.oracle.com/en/operating-systems/oracle-linux/6/admin/about-etc-resolve.html
Answer from Perplexity: pplx.ai/share
- sample
/etc/resolve.confin a container running in a Pod

- Name resolving can be enabled with services and service acts a layer 4 load balancer
- Each Service gets an ip address, But this is an virtual ip which means it never changes till you kill the service
- Service Official docs

- Service in k8s can be of following types
- Cluster IP: This is an internal ip address which works within k8s cluster
- Node Port: The service is exposed on every node in k8s cluster on a specific port
- Load Balancer: This generally works with cloud services, this creates a cloud native load balancer (rule)
- External Name: This is used for DNS records to be used externally
- Port definitions
- Services support only equality based selection for labels
Lets expose httpd containers using service
- Lets run the replicaset to create 5 pods of httpd
- lets create an internal service i.e. type is ClusterIP Refer Here
-
Now lets create one more service with type Node Port

