Kubernetes objects are persistent entities in the Kubernetes system. They represent the state of your cluster, including what containerized applications are running, the resources available to those applications, and the policies around how those applications behave.
- Smallest deployable units of computing in Kubernetes
- Can contain one or more containers
- Share storage and network resources
- Example:
apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
- An abstract way to expose an application running on a set of Pods
- Types: ClusterIP, NodePort, LoadBalancer, ExternalName
- Example:
apiVersion: v1 kind: Service metadata: name: my-service spec: selector: app: MyApp ports: - protocol: TCP port: 80 targetPort: 9376
- Directory accessible to containers in a pod
- Types: emptyDir, hostPath, configMap, secret, persistentVolumeClaim, etc.
- Virtual clusters backed by the same physical cluster
- Used for multi-tenancy and resource isolation
- Ensures that a specified number of pod replicas are running at any given time
- Usually used indirectly via Deployments
- Provides declarative updates for Pods and ReplicaSets
- Supports rolling updates and rollbacks
- Example:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
- Manages the deployment and scaling of a set of Pods
- Provides guarantees about the ordering and uniqueness of these Pods
- Used for stateful applications
- Ensures that all (or some) Nodes run a copy of a Pod
- Used for cluster-wide services like log collection or monitoring
- Creates one or more Pods and ensures that a specified number of them successfully terminate
- Used for batch processes
- Creates Jobs on a time-based schedule
- Stores non-confidential data in key-value pairs
- Can be used as environment variables, command-line arguments, or config files in a volume
- Similar to ConfigMap but for confidential data
- Stored in encrypted form
- PV: A piece of storage in the cluster provisioned by an administrator
- PVC: A request for storage by a user
- Automatically scales the number of pods in a replication controller, deployment, replica set or stateful set
- Provides constraints to limit resource consumption per containers or pods in a namespace
- Provides constraints that limit aggregate resource consumption per namespace
- Objects are typically defined in YAML files
- Use
kubectl apply -f <filename>
to create or update objects - Use
kubectl get <object-type>
to list objects - Use
kubectl describe <object-type> <object-name>
for detailed information - Use
kubectl delete <object-type> <object-name>
to delete objects
Understanding these objects and how they interact is crucial for effectively deploying and managing applications in Kubernetes.