Introduction to kubernetes resource management

In kubernetes, all content is abstractly called resources, and users need to manage k8s by operating resources

The essence of kubernetes is a cluster system. Users can deploy various services in the cluster. The so-called deployment is to run containers one by one in the k8s cluster, and run the executed program in the container.

The smallest management unit of kubernetes is a pod rather than a container, so the container can only be placed in the pod, and k8s generally does not directly manage the pod, but manages the pod through the pod controller

Dod can provide services, so it is necessary to consider how to access the services in the pod. Kubernetes provides two resources, service and ingress, to use this function. When pod data needs to be persisted, k8s also provides a variety of storage systems

Kubernetes cluster management (2)_nginx

Yaml language introduction

kubernetes中资源配置文件都是基于 YAML 语言编写,JSON 相对使用较少因为该文件无法注释

Yaml information:​ ​A brief introduction to the syntax of Yaml_Three Tigers' Technical Blog_51CTO Blog

Yaml conversion Json tool: http://json2yaml.com/convert-yaml-to-json

k8s resource management method

Imperative object management: directly use commands to operate on resources

kubectl run nginx-pod --image=nginx --port=80

Imperative object configuration: specify configuration files through commands to operate resources

kubectl create -f nginx-pod.yaml

Declarative object configuration: operate resources through apply commands and configuration files, which is equivalent to updating

kubectl apply -f nginx-pod.yaml

type

operation object

Applicable environment

advantage

shortcoming

imperative object management

a resource

test

Simple

Can only operate active objects, cannot audit, track

Imperative object configuration

a file

Production

audit, track

When the project is large, there are too many configuration files and the operation is complicated

Declarative object configuration

entire directory

Production

Support directory operations

Difficult to debug in unexpected situations

kubectl command parameters

Use the kubectl command to manage various resource objects in the cluster

kubectl command syntax:

kubectl [command] itype] [name] [flags]

command: what operation to perform on the resource, such as create, delete, get

type: Specifies the resource type, such as pod, deployment, service

name: the name of the specified resource **flags: * specifies additional optional parameters

kubectl common commands

# 查看所有 pod 资源
kubectl get pod
# 查看 pod 的 yaml 文件
kubectl get pod podname -o yaml
# 查看 pod 的 json 文件
kubectl get pod podname -o json
# 查看 pod 详细信息
kubectl get pod podname -o wide
查看所有的资源类型
kubectl api-resources

kubectl basic command parameters

Order

contain

create

create a resource

edit 

edit a resource

get

View a resource information

patch

update a resource

delete 

delete a resource

explain

Display resource documents

kubectl run and debug related command parameters

Order

meaning

run

run a specified image

expose

Expose resource as service

describe

View verbose output for resources

logs 

View the logs of the container in the pod

attach

into the running container

exec

into the container

cp

Copy files inside and outside pods

rollout

Manage the release of resources

scale

Scale up or down the number of pods

autoscale

The number of automatic jump pods

kubectl advanced command parameters

Order

meaning

apply

Update resource configuration

label

Update labels on resources

kubectl other commands

Order

meaning

cluster-info

display cluster information

version

show cluster version

cluster management

Resource Name

abbreviation

resource role

node

no

cluster components

namespace

ns

isolate pods

pod management

Resource Name

abbreviation

resource role

replicationcontrollers

rc

Controlling Pod Resources

replicasets

rs

Controlling Pod Resources

deployment

deploy

Controlling Pod Resources

daemonsets

ds

Controlling Pod Resources

jobs

Controlling Pod Resources

cronjobs

cj

Controlling Pod Resources

horizontalpodautoscalers

hpa

Controlling Pod Resources

statefulsets

sts

Controlling Pod Resources

service discovery

Resource Name

abbreviation

resource role

services

svc

Unified pod external interface

ingress

ing

Unified pod external interface

storage management

Resource Name

abbreviation

resource role

volumeattachments

storage

persistentvolumes

pv

storage

persistentvolumeclaims

pvc

storage

resource allocation

Resource Name

abbreviation

resource role

configmaps

cm

configuration

secrets

configuration

Summarize

Kubernetes Cluster Management (2)_Resource Management_02

Kubernetes Cluster Management (2)_Resource Management_03