Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the meaning of profile template in K8s

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about what the configuration file template means in K8s. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Deployment

Deployment provides declarative updates for Pod and Replica Set next-generation Replication Controller)

1. Configuration example # apiVersion: apps/v1 # versions prior to 1.9.0 use apps/v1beta2. You can use the command kubectl api-versions to view kind: Deployment # specify the role / type of the resource to create metadata: # metadata / attribute of the resource name: nginx-deployment # the name of the resource Must be unique in the same namespace namespace: xxxx # Namespace labels: app: demo # tag spec: replicas: 3 # number of copies 3 strategy: rollingUpdate: # # because the replicas is 3, the entire upgrade The number of pod is between 2 and 4 maxSurge: 1 # when rolling upgrade starts 1 pod maxUnavailable: 1 # maximum number of pod of Unavailable allowed when rolling upgrade selector: # define tag selector To deploy the pod to be managed (the one with this tag will be managed), you need to define matchLabels: app: web-server template: # in the pod template where the definition of Pod is metadata: labels: # Pod label app: web-server spec: # template specification containers:-name: nginx # container name image: Image address of nginx:1.12.1 # container command: ["/ bin/sh" "- c" "cat / etc/config/path/to/special-key"] # start command args: # start parameter -'- storage.local.retention=$ (STORAGE_RETENTION)'-'- storage.local.memory-chunks=$ (STORAGE_MEMORY_CHUNKS)' -'- config.file=/etc/prometheus/prometheus.yml' -'- alertmanager.url= http://alertmanager:9093/alertmanager' -'- web.external-url=$ (EXTERNAL_URL)'# if neither command nor args has written Then use the default configuration of Docker. # if command writes, but args does not, then the default configuration of Docker is ignored and only executes the command of the .yaml file (without any parameters). # if command does not write, but args does, then the command line of ENTRYPOINT configured by Docker by default will be executed, but the parameter to be called is args in .yaml. # if both command and args are written, then the default configuration of Docker is ignored and the .yaml configuration is used. ImagePullPolicy: IfNotPresent # IfNotPresent: default. If there is a local image, use the local image and do not pull it. If it does not exist, pull # Always: always pull # Never: only use the local image, and never pull livenessProbe: # indicates whether the container is in the live state. If LivenessProbe fails, LivenessProbe will notify kubelet that the corresponding container is unhealthy. Then kubelet will kill the container and do further operations according to the RestarPolicy. By default, LivenessProbe initializes the value to Success before the first detection. If container does not provide LivenessProbe, it is also considered to be Success HttpGet: path: / health # if there is no heartbeat detection interface, it is / port: 8080 scheme: HTTP initialDelaySeconds: 60 # # how long does it take to start detection timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 readinessProbe: readinessProbe: HttpGet: path: / health # if there is no heartbeat detection interface, it is / port: 8080 scheme: HTTP initialDelaySeconds: 30 # # how long does it take to start testing timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 resources: # # CPU memory limit Requests: cpu: 2 memory: 2048Mi limits: cpu: 2 memory: 2048Mi env: # # by means of environment variables Pass the pod= custom Linux OS environment variable directly-name: LOCAL_KEY # Local Key value: value-name: CONFIG_MAP_KEY # the office policy can use the configuration Key of configMap ValueFrom: configMapKeyRef: name: special-config # configmap find name for special-config key: special.type # find name for special-config key ports:-name: http containerPort: 8080 # for service exposure port volumeMounts: # mount volumes Defined disk-name: log-cache mount: / tmp/log-name: sdb # Common usage The volume is terminated with the container and mounted to a directory mountPath: / data/media-name: nfs-client-root # method to mount the hard disk directly, such as mounting the following nfs directory to / mnt/nfs mountPath: / mnt/nfs-name: example-volume-config # Advanced usage 1 Mount the log-script,backup-script of ConfigMap to a relative path path/to/... under the / etc/config directory respectively If there is a file with the same name, overwrite it directly. MountPath: / etc/config-name: rbd-pvc # Advanced usage 2, mounting PVC (PresistentVolumeClaim) # mounts ConfigMap directly as a file or directory using volume, where each key-value key-value pair generates a file, with key as the file name and value as the content Volumes: # Mount the disk to the above volumeMounts mount-name: log-cache emptyDir: {}-name: sdb # Mount the directory on the host hostPath: path: / any/path/it/will/be/replaced-name: example-volume-config # for the ConfigMap file content to the specified path so that the name items in configMap: name: example-volume-config # ConfigMap: -key: Key path: path/to/log-script # in log-script # ConfigMap A relative path under the specified directory path/to/log-script-key: Key path in backup-script # ConfigMap: path/to/backup-script # A relative path under the specified directory path/to/backup-script-name: nfs-client-root # for mounting NFS storage Storage type nfs: server: 10.42.0.55 # NFS server address path: / opt/public # showmount-e take a look at the path-name: rbd-pvc # mount PVC disk persistentVolumeClaim: claimName: rbd-pvc1 # mount the applied pvc disk 2. Service YAMLapiVersion: v1 # specify api version This value must be in kubectl api-versions kind: Service # specify the role / type to create the resource metadata: # metadata / attribute of the resource name: demo # the name of the resource In the same namespace, there must be a unique namespace: default # deployed in which namespace labels: # set resource specification field type: ClusterIP # ClusterIP type ports:-port: 8080 # service port targetPort: http # container exposed port protocol: TCP # protocol name: http # port name selector: # selector app: demo thank you for reading! This is the end of the article on "what is the meaning of the configuration file template in K8s". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report