Object: a bundle of software data that has an identity, a state, and a behavior
- Variables, fata structures, and specific functions
Entity: a person, palce, or thing with an identity and associated data
Persistent: that which lasts, despite server failures / network attacks
Kubernetes objects are persistent entities
- Pods
- Namespaces
- ReplicaSets
- Deployments
kubernetes objects consist of two main fields
- Object spec
- Provided by user
- Defines desired state
- Status
- Provided by Kubernetes
- Defines current state
Labels and selectors
Labels are key/value pairs attached to objects
- Intended for identification of objects
- Not unique
- Help organize and group objects
Label selectors are the core grouping method in Kubernetes
Namespaces and names
Namespaces provide a mechanism for isolateing groups of resources withing a single cluster
- Segregate cluster by team, project, etc
- Necessary with larger numbers of users
Namespaces provide a scope for object names
- Each object has a name
- Names are unique for a resource type within a namespace
Pods
Simplest unit in Kubernetes
Represents processes running in your cluster
Encapsulates one or more containers
Replicating a Pod serves to scale applications horizontally
apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
ReplicaSet
A ReplicaSet is a set of horizontally scaled running Pods
- A ReplicaSet configuration file defines:
- Number of replicas
- Pod template
- Selector to identify which Pods it can acquire
- Generally encapsulated by a Deployment
apiVersion: apps/v1 kind: ReplicaSet metadata: name: nignx-replicaset labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: naginx image: nginx:1.7.9 ports: - contianerPort: 80
Deployment
A Deployment is a higher-level object that provides updates for Pods and RelicaSets
Deployments:
- Run multiple replicas of an application
- Suitable for stateless applications
- Update triggers a rollout
apiVersion: apps/v1 kind: Deployment metadata: name: nignx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: naginx image: nginx:1.7.9 ports: - contianerPort: 80
Service
- Is a REST object, like Pods
- Is a logical abstraction for a set of Pods in a cluster
- Provides policies for accessing the Pods and cluster
- Acts as a load balancer across the Pods
- Is assigned a unique IP address for accessing applications deployed on Pods
- Eliminates the need for a separate Service discovery process
- Service properties:
- suppoerts multiple protocaols such as TCP(default), UDP, and others
- Support multiple port definitions
- The port number with the same name can vary in each backend Pod
- Can have an optional selector
- Optioally maps incoming ports to a targetPort

Why is a Service needed
- Pods in a cluster are volatile
- This volatility leads to discoverability issues because of changing IP addresses
- A Service keeps track of the changes and exposes a single IP address or a DNS name
- A Service utilizes selectors to target a set of Pods
- Native Kubernetes applications: Update API endpoints when there are changes in the Pods of a Service
- Non-native Kubernetes applications: Use a virtual-IP-based bridge or load balancer between the applications and the backend Pods
Service types
ClusterIP
- Is the default and most common Service type
- Is assigned a cluster-internal IP address to the ClusterIP Service that makes the Service only reachable within the cluster
- Cannot make requests to Service(Pods) from outside the cluster
- You set the ClusterIP address in the Service definition communication within the cluster
NodePort
- Is an extension of ClusterIP Service
- Creates and routes the incoming requests automatically to the ClusterIP Service
- Exposes the Service on each Node's IP address at a static port
- Exposes a single Service, with no load-balancing requirements for multiple services
LoadBalancer
- An extension of the NodePort Service, an External Load Balncer, or ELB, creates NodePort and CLusterIP Services automatically
- Integrates and automatically directs traffic to the NodePort Service with a cloud provider's ELB
- To expose a Service to the Internet, you need a new ELB with an IP address
- Use a cloud provide's ELB to host your cluster
External Name
- Maps to a DNS name and not to any selector
- Requires a `spec.externalName` parameter
- Maps the Service to contents of the externalName field that returns a CNAME record and its value
- Used to create a Service that represents an external storage and enable Pods from different namespaces to tlk to each other
Ingress
- Is an API objectI combined with a controller) tha provides routing rules to manage external users' access to multiple Services in a Kubernetes cluster
- In production, Ingress exposes applications to the Internet via port 80 or port 443
- An ELB is expensive and is managed outside the cluster while the cluster monitors Ingress
DaemonSet
- Is an object that makes sure that Nodes run a copy of a Pod
- As Nodes are added to a cluster, Pods are added to the Nodes
- Pods are garbage collected when removed from a cluster
- If you delete a DaemonSet, all Pods are removed
- Ideally used for storage, logs, and monitoring Nodes

StatefulSet
|
|
Job
- Is an object that creates Pods and tracks its completion process
- Jobs are retried until completed
- Deleting a Job will remove the created Pods
- Suspending a Job will delete its active Pods until the Job resumes
- A Job can run several Pods in parallel
- A CronJob is regularly used to create Jobs on an iterative schedule


浙公网安备 33010602011771号