Kubernetes Config File¶
- YAML config file to create and maintain components in a Kubernetes cluster
- It has 3 parts
- Stores the actual state of the component
- Automatically generated and added by K8s from the etcd which stores the status info of every component in the K8s cluster
Sample Config File¶
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: # label the deployment app: nginx spec: # specifications for the deployment replicas: 2 selector: # connect all pods with the given label matchLabels: app: nginx template: # configuration for the pods (config inside config) metadata: labels: app: nginx # label all the pods spec: # specifications for the pods containers: - name: nginx image: nginx:1.16 ports: - containerPort: 8080 # port at which the container is running
- Metadata contain labels which give key-value pairs to components
- Specifications contain selectors which select and connect components based on the labels
- Ports connect Services with Pods.
Describe the service The endpoints give the IP address and port of the pods that the service will forward the requests to.
❯ kubectl describe service nginx-service Name: nginx-service Namespace: default Labels: <none> Annotations: <none> Selector: app=nginx Type: ClusterIP IP Family Policy: SingleStack IP Families: IPv4 IP: 10.105.39.212 IPs: 10.105.39.212 Port: <unset> 80/TCP TargetPort: 8080/TCP Endpoints: 172.17.0.3:8080,172.17.0.4:8080 Session Affinity: None Events: <none>
Get the result of deployment¶
status: availableReplicas: 2 conditions: - lastTransitionTime: "2022-08-31T03:12:52Z" lastUpdateTime: "2022-08-31T03:12:52Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2022-08-31T03:12:51Z" lastUpdateTime: "2022-08-31T03:12:52Z" message: ReplicaSet "nginx-deployment-6986574f5f" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 1 readyReplicas: 2 replicas: 2 updatedReplicas: 2
Last updated: 2022-08-31