Basics
1. Introduction to Kubernetes Objects
Kubernetes objects are persistent entities in the Kubernetes system. They represent the state of your cluster and applications running on it. Understanding these objects is key to working effectively with Kubernetes.
2. Understanding YAML in Kubernetes
- What is YAML?: YAML, which stands for “YAML Ain't Markup Language,” is a human-readable data serialization standard that can be used in conjunction with all programming languages and is often used to write configuration files.
- YAML in Kubernetes: Kubernetes uses YAML as a format for specifying the configuration of objects within the cluster. It's preferred due to its readability and ease of use.
3. Pods
- Definition: The smallest deployable units created and managed by Kubernetes.
- Example YAML:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
4. Deployments and ReplicaSets
- Definition: Deployments manage the creation and scaling of ReplicaSets.
- Example YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx-container
image: nginx
5. Services
- Definition: Expose an application running on a set of Pods as a network service.
- Example YAML:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 9376
6. Ingress
- Definition: Manages external access to the services in a cluster.
- Example YAML:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
7. Volumes
- Definition: Directory containing data, accessible to containers in a Pod.
- Example YAML:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: my-volume
volumes:
- name: my-volume
hostPath:
path: /data
type: Directory
8. Namespaces
- Definition: Virtual clusters backed by the same physical cluster.
- Example YAML:
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace