k8s 官方 配置文件使用教程

官网链接为 https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#create-a-namespace

操作环境为minikube,需要提前执行下列操作启用metrics-server服务

minikube addons enable metrics-server

使用下列命令可以查看是否开启

kubectl get apiservices | grep metrics

大致流程,原理等需要参考https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#create-a-namespace 下内容

# 下载一个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
上一篇:JavaScript--阻止事件冒泡stopPropagation和cancelBubble


下一篇:Exception in thread "main" org.I0Itec.zkclient.exception.ZkAuthFailedException: Authentication failure is thrown while creating kafka topic