Each configuration has 3 parts
- Header and component type
- Api version
- Each component has a different api version. So look at documentation for it
- Component Types can be:
- Service
- Ingress
- Deployment
- Metadata
- name
- labels
- Specification
- Configurations
- replicas
- memory
- selectors
- ports
- template
- This has its own meta data and spec
- it is what tells what the pod would look like
- i.e. name of the container, image (like docker ocmpose)
- and more...
- Status
- This part is automatically generated by kubernetes
- This tells what is the desired state and what is the actual state
- This is the basis of self healing in kubernetes
- i.e. if
spec: replica: 2 but status has just one replica then kubernetes will keep trying to create new replica
connecting with labels and selectors
- metadata contains names
- spec contains selector
- in spec, selector → matchLabels; defines which labels in template are going to be connected and used
# DEPLOYMENT
apiVersion: apps/v1
kind: Deployment
metadata:
name: <u>***nginx-deployment***</u>
labels:
app: <u>***nginx***</u>
spec:
replicas: 2
selector:
matchLabels:
app: <u>***nginx***</u>
template:
metadata:
labels:
app: <u>***nginx***</u>
spec:
name: nginx
image: nginx:1.16
ports:
- containerPort: <u>***8080***</u>
...
# SERVICE
apiVersion: v1
kind: Service
metadata:
name: <u>***nginx-service***</u>
spec:
selector:
app: <u>***nginx***</u>
ports:
- protocol: TCP
port: 80
targetPort: <u>***8080***</u>
- "spec selector" from one config file is used in other config file.
- In the yamls above,
service -> spec -> selector -> app is same as selectors in deployment
- It basically tells, which pods belong to which service