基於kubernetes中的yaml管理應用的正確姿式

一條yaml中有不少字段,若是去背這些字段,其實也能背過,可是去寫一條yaml,也每每浪費不少的時間,也會出錯,其實咱們能夠用一條命令就能快速來寫一段自定義的yaml,工做中去修改相應的yaml也駕輕就熟,效率也會很高,接下來咱們來看一下nginx

[root@k8s-master ~]# kubectl create deployment nginx --image=nginx -o yaml --dry-run > my-deployment.yaml

-o yaml指定咱們的yaml文件vim

--dry-run 不在k8s中執行api

重定向到咱們的文件中app

[root@k8s-master ~]# vim my-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}

這是新建立一條yaml文件,咱們也能夠根據咱們的原有的pod來生成yaml,或者修改ide

[root@k8s-master ~]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bb7cd8db5-jrzgg   1/1     Running   0          93m
[root@k8s-master ~]# kubectl get deploy
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           93m
[root@k8s-master ~]# kubectl get deploy nginx -o yaml --export > my-deploy2.yaml

-o yaml:指定yaml文件spa

--export:輸出rest

Flag --export has been deprecated, This flag is deprecated and will be removed in future.code

[root@k8s-master ~]# vim my-deploy2.yaml
[root@k8s-master ~]# cat my-deploy2.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: null
  generation: 1
  labels:
    run: nginx
  name: nginx
  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginx
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status: {}

這樣的yaml效率很高,也不易出錯,但願能夠幫到你dns

相關文章
相關標籤/搜索