1. k8s的yaml文件到底有多复杂
Kubernetes创建、更新、删除资源等操作时均可以使用json或yaml文件进行操作,更新和删除可以依赖之前的文件进行更改,但是创建具有多变形,往往编辑起来比较复杂,容器出错,而且k8s的配置项实在太多,稍微不注意就会犯错。要写好一个yaml文件,你需要了解yaml的语法,需要掌握k8s的各种配置,对于一个k8s的初学者而言,这将是一件很难的事情。
比如我们看一个同时创建一个Deployment、Service、Ingress的yaml文件内容:
--- apiVersion: v1kind: Service metadata: labels: app: test-yaml name: test-yaml namespace: freeswitch spec: ports: - name: container-1-web-1 port: 8080 protocol: TCP targetPort: 8080 selector: app: test-yaml sessionAffinity: None type: ClusterIP --- apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: creationTimestamp: null name: test-yaml spec: rules: - host: test.com http: paths: - backend: serviceName: test-yaml servicePort: 8080 path: / --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: test-yaml name: test-yaml namespace: freeswitch spec: replicas: 3 selector: matchLabels: app: test-yaml strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 0 type: RollingUpdate template: metadata: annotations: info: test for yaml labels: app: test-yaml spec: affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: labelSelector: matchExpressions: - key: app operator: In values: - test-yaml topologyKey: kubernetes.io/hostname weight: 100 containers: - env: - name: TZ value: Asia/Shanghai - name: LANG value: C.UTF-8 image: nginx imagePullPolicy: Always lifecycle: {} livenessProbe: failureThreshold: 2 initialDelaySeconds: 30 periodSeconds: 10 successThreshold: 1 tcpSocket: port: 8080 timeoutSeconds: 2 name: test-yaml ports: - containerPort: 8080 name: web protocol: TCP readinessProbe: failureThreshold: 2 initialDelaySeconds: 30 periodSeconds: 10 successThreshold: 1 tcpSocket: port: 8080 timeoutSeconds: 2 resources: limits: cpu: 195m memory: 375Mi requests: |