One trick to complete the composition of YAML resource list files

One trick to complete the composition of YAML resource list files

1. Composition of YAML resource list file

1.1 How to view the metadata composition of resource objects

# kubectl explain 关键字

1.2 pod metadata composition

# kubectl explain pod

Under TypeMeta

Insert image description here

Pod ObjectMeta

Insert image description here

subspec

Insert image description here

1.3 Controller metadata composition

# kubectl explain deployment

Controller TypeMeta

Insert image description here

Deployment ObjectMeta

Insert image description here

DeploymentSpec

Insert image description here

1.4 Service metadata composition

# kubectl explain service

Service TypeMeta

Insert image description here

ObjectMeta

Insert image description here

ServiceSpec

Insert image description here

2. How to create resource objects through YAML resource manifest files?

2.1 Namespace

apiVersion: v1
kind: Namespace
metadata:
  name: test

2.2 Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
  - name: k8sonline1
    image: nginx:latest
    imagePullPolicy: IfNotPresent

2.3 Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx			
spec:				
  replicas: 1				
  selector:
    matchLabels:
      app: nginx			
  template:					  
    metadata:
      labels:
        app: nginx			
    spec:
      containers:
      - name: nginx
        image: nginx:1.15-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

2.4 Service

apiVersion: v1
kind: Service
metadata:
  name: deploy-nginx-svc
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx

3. How to completely manage YAML resource list file hosting?

Insert image description here

Insert image description here

# wget https://nginx.org/download/nginx-1.23.1.tar.gz
# mkdir nginxdir

# mv nginx-1.23.1.tar.gz nginxdir

# ls nginxdir/
nginx-1.23.1.tar.gz

# cd nginxdir/

# ls
nginx-1.23.1.tar.gz  ngx-fancyindex-0.4.3.tar.gz
# tar xf nginx-1.23.1.tar.gz
# tar xf ngx-fancyindex-0.4.3.tar.gz


# ls
nginx-1.23.1  nginx-1.23.1.tar.gz  ngx-fancyindex-0.4.3  ngx-fancyindex-0.4.3.tar.gz
# yum -y install gcc pcre-devel zlib-devel openssl-devel
# cd nginx-1.23.1/

# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

# ./configure --prefix=/usr/local/nginx  --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --add-module=/root/nginxdir/ngx-fancyindex-0.4.3/
# make && make install
# cat /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    
    
    worker_connections  1024;
}


http {
    
    
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
    
    
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
    
    
            root   html;
            fancyindex on;   添加
            fancyindex_exact_size off; 添加
            index  index;
        }

        #error_page  404              /404.html;
# /usr/local/nginx/sbin/nginx

Insert image description here

# cd /usr/local/nginx/html/

# ls
50x.html  index.html

# touch pod.yaml

# ls
50x.html  index.html  pod.yaml

Insert image description here

[root@k8s-master01 ~]# kubectl apply -f http://192.168.10.144/pod.yaml

Guess you like

Origin blog.csdn.net/weixin_47758895/article/details/132359772