容器相关
非root用户Docker与K8S
Containerd安装
Containerd常用命令
Docker
镜像创建
国内镜像仓库
容器创建(Dockerfile)
容器系统
docker配置
docker数据管理
docker网络管理
docker容器自启动
docker镜像加速
docker问题
搭建Portainer可视化界面
Docker Swarm
Swarm搭建Docker集群
Docker Compose
Docker Compose命令
Docker Compose模板
Docker Machine
Kubernetes常用命令
k8s部署(kubeadmin)
k8s高可用部署
MiniKube
k8s1.24部署(containerd)
k8s1.24部署(docker)
部署 Dashboard
Kuboard K8S管理台
k8s权限管理
k8s网络插件
私有仓密码镜像拉取
k8s集群管理
POD--基本单位
Pod模板
Pod生命周期
Pod健康检查
初始化容器(initContainer)
Deployment--Pod的管理
Deployment模板
Deployment升级与回滚
DaemonSet控制器
StatefulSet控制器(有状态)
JOB与CRONJOB
Service--发布服务
ingress-traefix
ingress-nginx
MetalLB
存储与配置
持久存储卷
配置存储卷
资源管理
标签、选择器与注解
资源预留
调度管理
自动扩容
Proxy API与API Server
Helm--K8S的包管理器
helm常用命令
自定义Chart
私有chart仓库
helm dashboard
K8S证书过期
K8S问题解决
Harbor安装
Harbor操作
Harbor问题
Harbor升级
Docker Registry安装
Docker Registry鉴权
Registry用Nginx代理SSL及鉴权
Docker Registry问题
Istio 服务网络
常用示例
Gateway【服务网关】
kiali 可视化页面
开启HTTPS
linkerd 服务网络
本文档使用MrDoc发布
返回首页
-
+
配置存储卷
2021年9月17日 17:14
admin
#ConfigMap >###传递普通的配置信息 ###创建ConfigMap apiVersion: v1 kind: ConfigMap metadata: name: special-config namespace: default data: special.how: very special.type: charm ###环境变量引用方式 #单一键值导入 env: - name: SPECIAL_LEVEL_KEY valueFrom: configMapKeyRef: name: special-config key: special.how - name: SPECIAL_TYPE_KEY valueFrom: configMapKeyRef: name: special-config key: special.type ================================================== #所有键值导入 envFrom: - configMapRef: name: env-config --- apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "-c", "env" ] env: - name: SPECIAL_LEVEL_KEY valueFrom: configMapKeyRef: name: special-config key: special.how - name: SPECIAL_TYPE_KEY valueFrom: configMapKeyRef: name: special-config key: special.type envFrom: - configMapRef: name: env-config restartPolicy: Never --- ###存储卷引用方式 apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "-c", "cat /etc/config/special.how" ] volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: special-config restartPolicy: Never ##注意: ####挂载目录下的文件名称,即为cm定义里的key值。 ####挂载目录下的文件的内容,即为cm定义里的value值。value可以多行定义,这在一些稍微复杂的场景下特别有用,比如 my.cnf。 ####如果挂载目录下原来有文件,挂载后将不可见(AUFS)。 --- #Secret >###传递敏感的、加密的配置信息 ##OpaqueSecret ####与configmap基本相同,区别在于key的value值需要base64加密后的值 ###创建 apiVersion: v1 kind: Secret metadata: name: special-config type:Opaque data: username: YWRtaW4= password: MTExMTEx ###环境变量引用方式 #单一键值导入 env: - name: SPECIAL_LEVEL_KEY valueFrom: secretKeyKeyRef: name: special-config key: special.how - name: SPECIAL_TYPE_KEY valueFrom: secretKeyKeyRef: name: special-config key: special.type ================================================== #所有键值导入 envFrom: - configMapRef: name: env-config --- ###存储卷引用方式 apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "-c", "cat /etc/config/special.how" ] volumeMounts: - name: secret-volume mountPath: /secret/allvalues volumes: - name: secret-volume secret: secretName: special-config --- ##imagePullSecret ####主要用来存储私有Docker Registry的认证信息。在设置Pod模板时,如果需要从私有仓库中拉取镜像,可以设置imagePullSecret属性为此类型的Secret,以作为仓库的登陆密钥。 kubectl create secret docker-registry <secret名称> --docker-server=<私有仓IP> --docker-username=<用户名> --docker-password=<登陆密码> --docker-email=<邮箱> ####查看 kubectl get secret <secret名称> -o yaml ![](/media//202109/2021-09-24104419264704.png) ####配置 vim examplePod #内容: apiVersion: v1 kind: Pod metadata: name: exampleSecret spec: containers: - name: test-container image: gcr.io/google_containers/busybox imagePullSecrets: - name: <secret名称> #填写之前创建的imagePullSecret --- #DownwardAPI >###主要作用是向Pod中运行的容器暴露Pod自身的信息。DownwardAPI允许容器在不使用K8S客户端或API的情况下获取有关自身或集群的信息 ####fieldRef |环境变量|名称 |--|-- |metadata.name|Pod 名称 |metadata.namespace|Pod 名称空间 |metadata.uid|Pod的UID |metadata.labels|Pod 标签 |metadata.annotations|Pod 的注解 |status.podIP|Pod的 IP |spec.serviceAccountName|Pod 服务帐号名称 |spec.nodeName|节点名称 |status.hostIP|节点 IP ####resourceFieldRef |环境变量|名称 |--|-- |limits.cpu|容器的CPU限制 |requests.cpu|容器的CPU请求 |limits.memory|容器的内存限制 |requests.memory|容器的内存请求 |limits.ephemeral-storage|容器的临时存储限制 |requests.ephemeral-storage|容器的临时存储请求 --- ###环境变量引用方式 apiVersion: v1 kind: Pod metadata: name: downward spec: containers: - name: main image: busybox command: ["sleep", "9999999"] resources: requests: cpu: 15m memory: 10Mi limits: cpu: 100m memory: 40Mi env: - name: POD_NAME #引用 pod manifest中的元数据名称字段,而不是设定一个具体的值 valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - name: NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName - name: SERVICE_ACCOUNT valueFrom: fieldRef: fieldPath: spec.serviceAccountName - name: CONTAINER_CPU_REQUEST_MILLICORES valueFrom: resourceFieldRef: resource: requests.cpu divisor: 1m - name: CONTAINER_MEMORY_LIMIT_KIBIBYTES valueFrom: resourceFieldRef: resource: limits.memory divisor: 1Ki --- ###存储卷引用方式 apiVersion: v1 kind: Pod metadata: #通过downloadApi卷来暴露这些标签和注解 name: downward labels: foo: bar annotations: key1: value1 key2: | multi line value spec: containers: - name: main image: busybox command: ["sleep", "9999999"] resources: requests: cpu: 15m memory: 10Mi limits: cpu: 100m memory: 40Mi volumeMounts: - name: downward mountPath: /etc/downward #挂载的位置 volumes: - name: downward #定义downwardAPI卷 downwardAPI: items: - path: "podName" #metadata.name字段将被写入到podName文件中 fieldRef: fieldPath: metadata.name - path: "podNamespace" fieldRef: fieldPath: metadata.namespace - path: "labels" fieldRef: fieldPath: metadata.labels - path: "annotations" fieldRef: fieldPath: metadata.annotations - path: "containerCpuRequestMilliCores" resourceFieldRef: containerName: main resource: requests.cpu divisor: 1m - path: "containerMemoryLimitBytes" resourceFieldRef: containerName: main resource: limits.memory divisor: 1
分享到: