YAML リソース リスト ファイルの作成を完了するための 1 つのコツ

YAML リソース リスト ファイルの作成を完了するための 1 つのコツ

1. YAMLリソース一覧ファイルの構成

1.1 リソースオブジェクトのメタデータ構成を表示する方法

# kubectl explain 关键字

1.2 ポッドメタデータの構成

# kubectl explain pod

TypeMeta の下

ここに画像の説明を挿入します

ポッドオブジェクトメタ

ここに画像の説明を挿入します

サブスペック

ここに画像の説明を挿入します

1.3 コントローラーのメタデータの構成

# kubectl explain deployment

コントローラのタイプメタ

ここに画像の説明を挿入します

デプロイメントオブジェクトメタ

ここに画像の説明を挿入します

導入仕様

ここに画像の説明を挿入します

1.4 サービスメタデータの構成

# kubectl explain service

サービスタイプメタ

ここに画像の説明を挿入します

オブジェクトメタ

ここに画像の説明を挿入します

サービススペック

ここに画像の説明を挿入します

2. YAML リソース マニフェスト ファイルを通じてリソース オブジェクトを作成するにはどうすればよいですか?

2.1 名前空間

apiVersion: v1
kind: Namespace
metadata:
  name: test

2.2 ポッド

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

2.3 導入

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 サービス

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

3. YAML リソース リスト ファイルのホスティングを完全に管理するにはどうすればよいですか?

ここに画像の説明を挿入します

ここに画像の説明を挿入します

# 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

ここに画像の説明を挿入します

# cd /usr/local/nginx/html/

# ls
50x.html  index.html

# touch pod.yaml

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

ここに画像の説明を挿入します

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

おすすめ

転載: blog.csdn.net/weixin_47758895/article/details/132359772