K8s之YAML文件
发表于:2024-11-21 作者:千家信息网编辑
千家信息网最后更新 2024年11月21日,Kubernetes支持YAML和JSON格式创建资源对象1,JSON格式用于接口之间消息的传递2,YAML格式用于配置和管理3,YAML是一种简洁的非标记性语言语法格式:缩进标识层级关系不支持制表符
千家信息网最后更新 2024年11月21日K8s之YAML文件
Kubernetes支持YAML和JSON格式创建资源对象
1,JSON格式用于接口之间消息的传递
2,YAML格式用于配置和管理
3,YAML是一种简洁的非标记性语言
语法格式:
缩进标识层级关系
不支持制表符(tab)缩进,使用空格缩进
通常开头缩进两个空格
字符后缩进一个空格,如冒号,逗号等
"---"表示YAML格式,一个文件的开始
"#"表示注释
`查看应用名称`[root@master1 ~]# kubectl api-versionsadmissionregistration.k8s.io/v1beta1apiextensions.k8s.io/v1beta1apiregistration.k8s.io/v1apiregistration.k8s.io/v1beta1apps/v1apps/v1beta1apps/v1beta2authentication.k8s.io/v1authentication.k8s.io/v1beta1authorization.k8s.io/v1authorization.k8s.io/v1beta1autoscaling/v1autoscaling/v2beta1autoscaling/v2beta2batch/v1batch/v1beta1certificates.k8s.io/v1beta1coordination.k8s.io/v1beta1events.k8s.io/v1beta1extensions/v1beta1networking.k8s.io/v1policy/v1beta1rbac.authorization.k8s.io/v1rbac.authorization.k8s.io/v1beta1scheduling.k8s.io/v1beta1storage.k8s.io/v1storage.k8s.io/v1beta1v1[root@master1 ~]# mkdir demo[root@master1 ~]# cd demo/[root@master1 demo]# vim nginx-deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: my-nginx labels: app: nginxspec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.15.4 ports: - containerPort: 80#插入内容后按Esc退出插入模式,输入:wq保存退出[root@master1 demo]# kubectl create -f my-nginx.yamldeployment.apps/my-nginx created[root@master1 demo]# kubectl get podsNAME READY STATUS RESTARTS AGE`my-nginx-d55b94fd-kc2gl 1/1 Running 0 47s``my-nginx-d55b94fd-tkr42 1/1 Running 0 47s`nginx-6c94d899fd-8pf48 1/1 Running 0 23hnginx-deployment-5477945587-f5dsm 1/1 Running 0 22hnginx-deployment-5477945587-hmgd2 1/1 Running 0 22hnginx-deployment-5477945587-pl2hn 1/1 Running 0 22h[root@master1 demo]# vim my-nginx-service.yamlapiVersion: v1kind: Servicemetadata: name: my-nginx-service labels: app: nginxspec: type: NodePort ports: - port: 80 targetPort: 80 selector: app: nginx#插入内容后按Esc退出插入模式,输入:wq保存退出[root@master1 demo]# kubectl create -f my-nginx-service.yamlservice/my-nginx-service created`查看服务`[root@master1 demo]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.0.0.1 443/TCP 8d`my-nginx-service NodePort 10.0.0.210 80:40377/TCP 20s`nginx-service NodePort 10.0.0.242 80:40422/TCP 33h
1.自动测试命令的正确性,并不执行创建:
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-runkubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.deployment.apps/my-nginx created (dry run)
2.查看生成yaml格式:
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o yamlkubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.apiVersion: apps/v1beta1kind: Deploymentmetadata: creationTimestamp: null labels: run: my-nginx name: my-nginxspec: replicas: 2 selector: matchLabels: run: my-nginx strategy: {} template: metadata: creationTimestamp: null labels: run: my-nginx spec: containers: - image: nginx name: my-nginx ports: - containerPort: 80 resources: {}status: {}
3.生成yaml模板文件:
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o yaml > nginx-deploy.yamlkubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
4.导出json格式文件:
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o jsonkubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.{ "kind": "Deployment", "apiVersion": "apps/v1beta1", "metadata": { "name": "my-nginx", "creationTimestamp": null, "labels": { "run": "my-nginx" } }, "spec": { "replicas": 2, "selector": { "matchLabels": { "run": "my-nginx" } }, "template": { "metadata": { "creationTimestamp": null, "labels": { "run": "my-nginx" } }, "spec": { "containers": [ { "name": "my-nginx", "image": "nginx", "ports": [ { "containerPort": 80 } ], "resources": {} } ] } }, "strategy": {} }, "status": {}}
5.将现有的资源生成模板导出:
[root@master1 demo]# kubectl get deploy/nginx --export -o yamlapiVersion: extensions/v1beta1kind: Deploymentmetadata: annotations: deployment.kubernetes.io/revision: "2" creationTimestamp: null generation: 1 labels: run: nginx name: nginx selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginxspec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 2 selector: matchLabels: run: nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: run: nginx spec: containers: - image: nginx:1.14 imagePullPolicy: Always name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30status: {}
6.保存到文件中:
[root@master1 demo]# kubectl get deploy/nginx --export -o yaml > my-deploy.yaml
7.查看字段帮助信息:
[root@master1 demo]# kubectl explain pods.spec.containersKIND: PodVERSION: v1RESOURCE: containers <[]Object>DESCRIPTION: List of containers belonging to the pod. Containers cannot currently be added or removed. There must be at least one container in a Pod. Cannot be updated. A single application container that you want to run within a pod.FIELDS: args <[]string> Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell command <[]string> Entrypoint array. Not executed within a shell. The docker image's ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell env <[]Object> List of environment variables to set in the container. Cannot be updated. envFrom <[]Object> List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated. image Docker image name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets. imagePullPolicy Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images lifecycle
格式
文件
空格
生成
内容
模式
模板
资源
支持
输入
简洁
两个
之间
信息
冒号
制表符
名称
命令
字段
字符
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发开发票内容怎么写
服务器攻击网站
2022年数据库占有率排名
激光雕刻机软件开发
检索我国标准的全文数据库
福建常见软件开发单价
服务器插网卡光模块不亮
图片放到文件服务器访问过慢
丰台区定制软件开发经历
手机软件开发工具包下载
网络安全自查问卷
提升网络安全放心银行
mail服务器软件
食谱数据库大全
科技互联网八卦
服务器磁盘有没有阵列有啥区别
ACDC下载软件开发
档案局专题数据库建设情况
数据库远程连接方式
转阵营服务器
浦东新区服务器回收公司
国内研发的软件开发工具有
郑州工控软件开发价钱是多少
国家网络安全宣传周活动接待工作
网络安全歌谣顺口溜新闻
网络安全问题监管
威海ios软件开发外包公司
医学论文有哪些数据库查询
传奇多久开一次服务器
数据库安全 推断