Relevant concepts

Pod

A Pod is the smallest unit that can be created and managed in a K8S system. A Pod (like a pea Pod) is a group that contains one or more containers (for example, a Docker container), shared storage/network, and specifications for how to run the container. Containers in a Pod share an IP address and port space and can look each other up via localhost. Containers in different Pods have different IP addresses, and Pods communicate with each other through IP addresses

Pod characteristics

  • Minimum deployed unit
  • A Pod consists of one or more containers.
  • Containers in a POD are shared network namespaces
  • Pod is ephemeral
  • Each Pod contains one or more closely related user business containers

Yaml Configuration field description

  • ApiVersion: INDICATES the API version
  • Kind: Indicates the Pod resource type
  • Metadata Indicates the resource metadata
  • Spec Resource specifications
  • ImagePullPolicy Rule for drawing images
    • IfNotPresent: Default value, pulled only when the image does not exist on the host
    • Always: The image is pulled again each time a Pod is created
    • Never: Pod Never actively pulls the image
  • RestartPolicy Restart rule
    • Always: Always restart the container when the container terminates after exit, default policy [nginx, etc., need continuous service]
    • OnFailure: Restarts the container only when the container exits unexpectedly (exit status code is not 0).
    • Never: Never restart the container when the container terminates.

How to write YAML files quickly

Kubectl create deployment web --image=nginx -o yaml --dry-runCopy the code

If you want to output a file

kubectl create deployment web --image=nginx -o yaml --dry-run > hello.yaml
Copy the code

Export a YAML configuration file for an existing Pod

kubectl get deploy nginx -o=yaml --export > nginx.yaml
Copy the code

Create pods using YAML

kubectl apply -f nginx.yaml
Copy the code

Expose ports for external access

kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=nginx-service -o yaml > nginx-service.yaml
Copy the code

Delete a POD

// kubectl get deployment -n XXX // kubectl delete deployment jenkins2Copy the code

Controller

Controller is an object that manages and runs containers on a cluster, and Pod is used to implement the operation and maintenance of applications, such as elastic scaling and rolling upgrade, etc. The relationship between Pod and Controller is established through the label label

apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: web name: web spec: replicas: 1 // a copy of selector: matchLabels: app: web // control Pod label strategy: {} template: metadata: creationTimestamp: null labels: app: web spec: containers: - image: nginx name: nginx resources: {} status: {}Copy the code

Stateless and stateless:

  • Think that pods are all the same
  • There is no order requirement
  • You don’t have to worry about which Pod you’re running on
  • Feel free to scale and expand

A stateful

  • All of these factors need to be considered

Example: order such as MySQL master slave

Deployment

Deployment is mainly used to deploy stateless applications

StatefulSet

Statefulset is primarily used to deploy stateful applications. For pods in StatefulSet, each Pod mounts its own independent storage, and if one fails, a Pod with the same name is started from another node, with the storage mounted to the original Pod continuing to be serviced in its state. Services suitable for StatefulSet include database services MySQL and PostgreSQL, cluster management services Zookeeper, ETCD and other stateful services

DaemonSet

DaemonSet, a back-end support service, is used to deploy daemons

Replication Controller

Replication Controller, RC for short, is a Replication Controller in K8S. RC is the earliest API object in K8S cluster to guarantee Pod high availability. Monitor running pods to ensure that a specified number of Pod copies are running in the cluster. The specified number can be multiple or one; Less than the specified number, RC starts a new Pod copy; More than the specified number, RC kills extra Pod copies

Replica Set

Replica Set is called RS. RS is the next generation OF RC and provides the same high availability capability, but the difference is that RS is coming from behind and can support a wider variety of matching modes. Replica set objects are not typically used on their own, but as an ideal state parameter for Deployment

Job

Service

Define a group of Pod access rules function: 1 service discovery 2 define a group of Pod access rules (load balancing)

ClusterIP: internal use NodePort: external access NodeBalance: external public cloud access

Ingress

Pod and Ingress are associated through a Service, which acts as a unified entry point and is associated with a set of pods by the Service

Helm

Helm is a package management tool for K8S, which makes it easy to deploy yamL files to K8S, making service deployment more convenient and efficient.

Solve a problem:

  • These YAMLS can be managed as a whole using helm
  • Realize efficient reuse of YAML
  • Version management using the HELM application level

Three concepts (1) Helm: a command line tool (2) Chart packages YAML as a collection of YAML (3) Deploy entity application-level version management based on Chart

K8S pulls images from private repositories

Pull images from private repositories

Cluster management tool Kubectl

Kubernetes cluster management tool Kubectl

The resources

  • Cluster Environment Installation
  • Kubernetes Chinese documentation
  • Kubernetes learning video
  • Latest K8S video
  • notes
  • K8S Javascript API