官网连接为 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