k8s之yaml详解
配置介绍
使用yaml格式创建服务,更容易管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| apiVersion: extensions/v1beta1 kind: Deployment metadata: name: cango-demo namespace: cango-prd labels: app: cango-demo spec: replicas: 3 strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 template: metadata: labels: app: cango-demo sepc: containers: - name: cango-demo image: swr.cn-east-2.myhuaweicloud.com/cango-prd/cango-demo:0.0.1-SNAPSHOT command: [ "/bin/sh","-c","cat /etc/config/path/to/special-key" ] args: - '-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)' imagePullPolicy: IfNotPresent livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 readinessProbe: readinessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 30 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 resources: requests: cpu: 2 memory: 2048Mi limits: cpu: 2 memory: 2048Mi env: - name: LOCAL_KEY value: value - name: CONFIG_MAP_KEY valueFrom: configMapKeyRef: name: special-config key: special.type ports: - name: http containerPort: 8080 volumeMounts: - name: log-cache mount: /tmp/log - name: sdb mountPath: /data/media - name: nfs-client-root mountPath: /mnt/nfs - name: example-volume-config mountPath: /etc/config - name: rbd-pvc
volumes: - name: log-cache emptyDir: {} - name: sdb hostPath: path: /any/path/it/will/be/replaced - name: example-volume-config configMap: name: example-volume-config items: - key: log-script path: path/to/log-script - key: backup-script path: path/to/backup-script - name: nfs-client-root nfs: server: 10.42.0.55 path: /opt/public - name: rbd-pvc persistentVolumeClaim: claimName: rbd-pvc1
|
nginx安装例子
创建 deployment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| apiVersion: apps/v1
kind: Deployment metadata: name: nginx-deployment namespace: default labels: web: nginx123
spec:
replicas: 3
selector:
matchLabels: app: nginx
template: metadata: labels: app: nginx
spec: containers: - name: nginx image: nginx:1.12 ports: - containerPort: 80
|
创建 service
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| apiVersion: v1 kind: Service metadata: name: nginx-service namespace: default
labels: app: nginx spec: ports: - port: 89 targetPort: 80 selector: app: nginx
|
常用命令
1 2 3 4 5 6 7 8
| kubectl create -f nginx_service.yaml
kubectl apply -f nginx_service.yaml
kubectl delete -f nginx_service.yaml
|