官網連接爲 https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#create-a-namespaceredis
操做環境爲minikube,須要提早執行下列操做啓用metrics-server服務docker
minikube addons enable metrics-server
使用下列命令能夠查看是否開啓api
kubectl get apiservices | grep metrics
大體流程,原理等須要參考https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#create-a-namespace 下內容curl
# 下載一個redis的配置文件 ➜ curl -OL https://k8s.io/examples/pods/config/redis-config % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 185 100 185 0 0 51 0 0:00:03 0:00:03 --:--:-- 51 100 43 100 43 0 0 11 0 0:00:03 0:00:03 --:--:-- 183 ➜ ls a.dockerfile a.tar b.tar redis-config server.js # 使用kubectl create configmap命令建立一個configmap文件 ➜ kubectl create configmap example-redis-config --from-file=redis-config configmap "example-redis-config" created # 將configmap文件輸出爲yaml ➜ kubectl get configmap example-redis-config -o yaml apiVersion: v1 data: redis-config: maxmemory 2mb maxmemory-policy allkeys-lru kind: ConfigMap metadata: creationTimestamp: 2019-03-19T08:51:28Z name: example-redis-config namespace: default resourceVersion: "34018" selfLink: /api/v1/namespaces/default/configmaps/example-redis-config uid: 2f58973b-4a24-11e9-b7b5-080027d6b830 # 根據redis-pod.yaml文件來建立一個pod ➜ kubectl create -f https://k8s.io/examples/pods/config/redis-pod.yaml pod "redis" created ➜ kubectl get pods NAME READY STATUS RESTARTS AGE kubernetes-bootcamp-b4d449bd-vlnpd 1/1 Running 0 1h redis 0/1 ContainerCreating 0 36m # redis-pod.yaml文件的內容以下,能夠看到volumes下面的configMap就是來自於上面建立的configMap # 而configMap來自於最先的redis-config apiVersion: v1 kind: Pod metadata: name: redis spec: containers: - name: redis image: kubernetes/redis:v1 env: - name: MASTER value: "true" ports: - containerPort: 6379 resources: limits: cpu: "0.1" volumeMounts: - mountPath: /redis-master-data name: data - mountPath: /redis-master name: config volumes: - name: data emptyDir: {} - name: config configMap: name: example-redis-config items: - key: redis-config path: redis.conf