一招搞定YAML资源清单文件构成
一、 YAML资源清单文件构成
1.1 如何查看资源对象的元数据组成
# kubectl explain 关键字
1.2 pod元数据组成
# kubectl explain pod
Pod TypeMeta
Pod ObjectMeta
podSpec
1.3 controller元数据组成
# kubectl explain deployment
Controller TypeMeta
Deployment ObjectMeta
DeploymentSpec
扫描二维码关注公众号,回复:
17013497 查看本文章
1.4 service元数据组成
# kubectl explain service
Service TypeMeta
ObjectMeta
ServiceSpec
二、如何通过YAML资源清单文件创建资源对象?
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
三、如何彻底搞定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