Kubernetes外挂配置管理—ConfigMap介绍

K8s ConfigMaps为容器设置备份和还原 Kubernetes中的容器本身是短暂的,这意味着容器中的数据仅在容器启动期间保留,并且在部署失败或pod退出等情况下立即清除。因此,对于几乎所有有状态的应用程序,您肯定需要一个持久存储,我们将使用Kubernete集群中的持久卷来定义它。因此,目标是对数据库进行定时时间点备份,然后从现有可用备份执行恢复,从而完成成功的灾难恢复场景。我们选择使用MySQL数据库。现在,我希望上面的代码片段回答了其中一个问题-\u ConfigMaps装载到pod发生在容器启动之前,这就是为什么我们能够将其作为入口点执行。 阅读详情

 

目录贴:Kubernetes学习系列

  其他容器编排调度工具会大谈特谈“轻应用”、“十二要素应用”,这样就势必会对企业级复杂应用做很大的改动。Kubernetes是为了解决“如何合理使用容器支撑企业级复杂应用”这个问题而诞生的,所以它的设计理念是要支持绝大多数应用的原生形态。例如,很多应用程序的配置需要通过配置文件,命令行参数和环境变量的组合配置来完成(“十二要素应用”等均要求去配置)。这些配置应该从image内容中解耦,以此来保持容器化应用程序的可移植性。ConfigMap API资源提供了将配置数据注入容器的方式,同时保证该机制对容器来说是透明的。ConfigMap可以被用来保存单个属性,也可以用来保存整个配置文件或者JSON二进制大对象。

  ConfigMap API资源存储键/值对配置数据,这些数据可以在pods里使用。ConfigMap跟Secrets类似,但是ConfigMap可以更方便的处理不包含敏感信息的字符串。示例如下:

复制代码

kind: ConfigMap
apiVersion: v1
metadata:
  creationTimestamp: 2016-02-18T19:14:38Z
  name: example-config
  namespace: default
data:
  example.property.1: hello
  example.property.2: world
  example.property.file: |-
    property.1=value-1
    property.2=value-2
    property.3=value-3

复制代码

  通过示例代码可以看到:ConfigMap可以包含细粒度的配置项,如:example.property.1;也可以包含粗粒度的配置文件,如:example.property.file。

1、创建ConfigMap

1.1 从文件夹创建

复制代码

[root@k8s-master propertirs]# cat /home/yaml/propertirs/game.properties 
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
[root@k8s-master propertirs]# cat /home/yaml/propertirs/ui.properties 
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
[root@k8s-master propertirs]# kubectl create configmap game-config --from-file=/home/yaml/propertirs/
configmap "game-config" created
[root@k8s-master propertirs]# kubectl describe configmaps game-config  
#该方法只能得到ConfigMap的Key和size
Name:        game-config
Namespace:    default
Labels:        <none>
Annotations:    <none>

Data
====
ui.properties:        83 bytes
game.properties:    158 bytes
#若想得到详细信息,可通过以下命令:
[root@k8s-master propertirs]# kubectl get configmaps game-config -o yaml
apiVersion: v1
data:
  game.properties: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
  ui.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:22:34Z
  name: game-config
  namespace: default
  resourceVersion: "3002770"
  selfLink: /api/v1/namespaces/default/configmaps/game-config
  uid: a04f90f0-0de5-11e7-b3d5-fa163ebba51b

复制代码

1.2 从文件创建

复制代码

[root@k8s-master propertirs]# kubectl create configmap game-config-2 --from-file=/home/yaml/propertirs/game.properties --from-file=/home/yaml/propertirs/ui.properties
configmap "game-config-2" created
[root@k8s-master propertirs]# kubectl get configmaps game-config-2 -o yaml
apiVersion: v1
data:
  game.properties: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
  ui.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:30:15Z
  name: game-config-2
  namespace: default
  resourceVersion: "3003415"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-2
  uid: b2e4dfab-0de6-11e7-b3d5-fa163ebba51b

复制代码

1.3  指定data中的key

复制代码

[root@k8s-master propertirs]# kubectl create configmap game-config-3 --from-file=game-special-key=/home/yaml/propertirs/game.properties
configmap "game-config-3" created
[root@k8s-master propertirs]# kubectl get configmaps game-config-3 -o yaml
apiVersion: v1
data:
  game-special-key: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:33:23Z
  name: game-config-3
  namespace: default
  resourceVersion: "3003678"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-3
  uid: 2345dad3-0de7-11e7-b3d5-fa163ebba51b

复制代码

1.4  指定具体的值

复制代码

[root@k8s-master propertirs]# kubectl create configmap game-config-4 --from-literal=special.user=zhenyu --from-literal=special.passwd=yaodidiao
configmap "game-config-4" created
[root@k8s-master propertirs]# kubectl get configmaps game-config-4 -o yaml
apiVersion: v1
data:
  special.passwd: yaodidiao
  special.user: zhenyu
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:36:12Z
  name: game-config-4
  namespace: default
  resourceVersion: "3003915"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-4
  uid: 8802f6d2-0de7-11e7-b3d5-fa163ebba51b

复制代码

2、使用ConfigMap

2.1 环境变量或参数

  创建一个Pod,并将一个已经创建好的ConfigMap作为环境变量,注入到Pod中。

复制代码

[root@k8s-master propertirs]# kubectl get configmaps game-config-4 -o yaml
apiVersion: v1
data:
  special.passwd: yaodidiao
  special.user: zhenyu
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:36:12Z
  name: game-config-4
  namespace: default
  resourceVersion: "3003915"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-4
  uid: 8802f6d2-0de7-11e7-b3d5-fa163ebba51b
[root@k8s-master propertirs]# cat testEnv.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: testenv
    role: master
  name: testenv
spec:
  containers:
    - name: testenv
      image: busybox
      imagePullPolicy: IfNotPresent
      env:
        - name: SPECIAL_USER
          valueFrom:
            configMapKeyRef:
              name: game-config-4
              key: special.user
      command:
      - sleep
      - "360000"
[root@k8s-master propertirs]# kubectl create -f testEnv.yaml 
pod "testenv" created
[root@k8s-master propertirs]# kubectl exec -ti testenv sh
/ # echo $SPECIAL_USER
zhenyu
/ #

复制代码

2.2 挂载文件数据卷

复制代码

[root@k8s-master propertirs]# kubectl get configmaps game-config -o yaml
apiVersion: v1
data:
  game.properties: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
  ui.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T03:22:34Z
  name: game-config
  namespace: default
  resourceVersion: "3002770"
  selfLink: /api/v1/namespaces/default/configmaps/game-config
  uid: a04f90f0-0de5-11e7-b3d5-fa163ebba51b
[root@k8s-master propertirs]# cat testVolume.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: testvolume
    role: master
  name: testvolume
spec:
  containers:
    - name: testvolume
      image: busybox
      imagePullPolicy: IfNotPresent
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
      command:
      - sleep
      - "360000"
  volumes:
    - name: config-volume
      configMap:
        name: game-config
[root@k8s-master propertirs]# kubectl create -f testVolume.yaml 
pod "testvolume" created
[root@k8s-master propertirs]# kubectl exec -ti testvolume sh
/ # cd /etc/config/
/etc/config # ls
game.properties  ui.properties
/etc/config # cat game.properties 
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
/etc/config # cat ui.properties 
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
/etc/config #

复制代码

2.3 挂载信息数据卷

复制代码

[root@k8s-master propertirs]# cat testVolume.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: testvolume
    role: master
  name: testvolume
spec:
  containers:
    - name: testvolume
      image: busybox
      imagePullPolicy: IfNotPresent
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
      command:
      - sleep
      - "360000"
  volumes:
    - name: config-volume
      configMap:
        name: game-config-4
[root@k8s-master propertirs]# kubectl get  configmaps game-config-4 -o yaml
apiVersion: v1
data:
  special.passwd: yaodidiao
  special.user: zhenyuyaodidiao
kind: ConfigMap
metadata:
  creationTimestamp: 2017-03-21T06:29:29Z
  name: game-config-4
  namespace: default
  resourceVersion: "3018779"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-4
  uid: bd086dca-0dff-11e7-b3d5-fa163ebba51b
[root@k8s-master propertirs]# kubectl create -f testVolume.yaml 
pod "testvolume" created
[root@k8s-master propertirs]# kubectl exec -ti testvolume sh
/ # cd /etc/config/
/etc/config # ls
special.passwd  special.user
/etc/config # cat special.user 
zhenyuyaodidiao/etc/config # 
/etc/config # exit

复制代码

2.4 热更新

  当ConfigMap以数据卷的形式挂载进Pod的时,这时更新ConfigMap(或删掉重建ConfigMap),Pod内挂载的配置信息会热更新。这时可以增加一些监测配置文件变更的脚本,然后reload对应服务。

13、k8s集群中ETCD备份和恢复 etcd备份和恢复 阅读详情

相关推荐

六、Kubernetes配置管理ConfigMap、Secret

应用部署的一个最佳实践是将应用所需的配置信息与程序分离,这样可以使应用程序被更好地复用,通过不同的配置也能实现更灵活的功能。将应用打包为容器镜像后,可以通过环境变量或者外挂文件的方式在创建容器时进行配置注入,但在大规模容器集群的环境中,对多个容器进行不同的配置将变得非常复杂。配置管理问题风险:配置文件写在代码里,管理不方便,且有风险。 配置文件分离,是主要作用,独立配置文件,管理和操作都方便。如果有热加载,变更配置文件,不需要影响pod。ConfigMap用于明文配置文件,redis文件等。Secret用于

Cyan_Jiang的博客 1024

K8S——存储ConfigMap

ConfigMap API 给我们提供了向容器中注入配置信息的机制,ConfigMap 可以被用来保存单个属性,也可以用来保存整个配置文件或者 JSON 二进制大对象。ConfigMap 功能在 Kubernetes1.2 版本中引入,许多应用程序会从配置文件、命令行参数或环境变量中读取配置信息。这个参数可以使用多次,你可以使用两次分别指定上个实例中的那两个配置文件,效果就跟指定整个。参数传递配置信息,该参数可以使用多次,格式如下。只要指定为一个文件就可以从单个文件中创建。也要同时删除pod,再重新创建。

benziwu的博客 835

[Kubernetes]6. k8s Pod配置管理ConfigMap & Secret以及传递环境变量的使用,k8s的命名空间以及使用kubens管理命名空间

k8s Pod配置管理ConfigMap & Secret以及传递环境变量的使用,k8s借助命令行配置管理ConfigMap & Secret,以及借助腾讯云面板配置管理ConfigMap & Secret,k8s的命名空间以及使用kubens管理命名空间

资深系统架构,深耕高并发研发与 AI 大模型工程化落地。技术栈以 Python (AI/NLP/RAG/Agent) 与 Golang (高并发架构) 为双核心,兼具 PHP 大型应用经验。专注算法落地、复杂系统设计及团队技术赋能 1534

K8S资源对象备份恢复流程

使用恢复工具恢复ConfigMap/Secret。API Server向ETCD发送恢复请求。API Server向ETCD发送恢复请求。恢复工具向API Server发送请求。恢复工具向API Server发送请求。恢复ConfigMap/Secret。恢复ConfigMap/Secret。API Server返回恢复结果。API Server返回恢复结果。使用恢复工具恢复PV/PVC。ETCD返回恢复结果。ETCD返回恢复结果。

weixin_44725869的博客 615

拆开一个烧坏的IGBT模块,手把手教你识别过压、过流、过温的“案发现场”

本文详细解析了IGBT模块失效分析的实战技巧,通过观察铝层熔化纹路、焊锡溢出形态等物理痕迹,手把手教你识别过压、过流、过温的典型失效模式。文章提供了从基础工具包到现场快速诊断的完整流程,帮助工程师精准定位IGBT模块失效的根本原因。

weixin_30655569的博客 427

dq轴坐标系下的电路方程

dq轴坐标系下的电路方程 dq轴坐标系是一种常见的电路方程,但是再dq轴坐标系下电路元件的电压电流dq轴存在一定的耦合,本文针对三相电路推导了dq轴坐标系下的电路电路方程进行一个推导,首先先列出来派克变换的公式 派克变换 [AdAqA0]=23[cos⁡(θ)cos⁡(θ−2π/3)cos⁡(θ+2π/3)−sin⁡(θ)−sin⁡(θ−2π/3)−sin⁡(θ+2π/3)1/21/21/2][AaAbAc]\left[\begin{array}{c}A_d\\A_q\\A_0 \end{array}\ri

Mr.Young的博客 1万+

K8s存储-----(一)Configmap配置管理

Configmap用于保存配置数据,以键值对形式存储。 configMap 资源提供了向 Pod 注入配置数据的方法。 旨在让镜像和配置文件解耦,以便实现镜像的可移植性和可复用性。 典型的使用场景: 填充环境变量的值 设置容器内的命令行参数 填充卷的配置文件 创建ConfigMap的方式有4种 (1)使用字面值创建 kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2 kubect

qq_41582883的博客 970

保姆级教程:用STM32CubeMX HAL库搞定ESP8266连接,附串口printf调试全流程

本文提供了一份详细的STM32CubeMX HAL库教程,指导开发者如何实现ESP8266无线模块的连接与调试。从开发环境搭建、串口配置到AT指令通信解析,涵盖了物联网开发中的关键步骤和常见问题解决方案,帮助开发者快速掌握STM32与ESP8266的集成技术。

weixin_28273593的博客 504

深入玩转K8S之如何实现外挂配置管理—ConfigMap

还是老规矩先来了解下什么是ConfigMap,那么在了解ConifigMap的同时也得了解下另一个概念就是Secret。可能会有人说,你这不是在讲ConfigMap么,怎么还要扯Secret,别着急等我慢慢道来,那为什么要有这两个东西呢?因为在实际应用的过程中,我们经常会需要传一些配置给我们的应用,比如配置文件变更啊、用户名密码啊等等之类的。可能这个时候就会有童鞋说了我们有好多种方案可以实现啊,比...

weixin_33884611的博客 1109

SAP BSP网页开发入门:从SE80创建到MVC实战(附成品展示)

本文详细介绍了SAP BSP网页开发的入门与实战,从SE80环境搭建到MVC架构实现的全流程。通过具体案例和代码示例,帮助开发者掌握业务服务器页面(BSP)技术,提升SAP Web化转型中的开发效率,适用于需要扩展SAP功能的企业场景。

x1y2z的博客 1万+

麻雀搜索算法(SSA)详解:从鸟群智能到优化实践

麻雀搜索算法(SSA)是一种新型群智能优化算法,模拟麻雀群体的觅食行为和反捕食机制。该算法将优化问题转化为麻雀群体对食物源的搜索过程,通过发现者、加入者和警戒者的角色分工实现高效优化。SSA具有原理新颖、参数合理、收敛快速等特点,在函数优化、工程设计和机器学习等领域展现出良好应用前景。算法通过数学模型模拟麻雀的觅食策略,包括发现者全局探索、加入者局部开发和警戒者危险预警机制,有效平衡了全局搜索与局部开发能力。SSA相比传统优化算法具有更好的收敛性和优化效果。

qq_42212808的博客 1074

07Kubernetes配置管理ConfigMap

应用部署的一个最佳实践是将应用所需的配置信息与程序分离,这样可以使应用程序被更好地复用,通过不同的配置也能实现更灵活的功能。将应用打包为容器镜像后,可以通过环境变量或者外挂文件的方式在创建容器时进行配置注入,但在大规模容器集群的环境中,对多个容器进行不同的配置将变得非常复杂。二、configMap简介(缩写:cm)ConfigMap是一种 API 对象,用来将非机密性的数据保存到键值对中。使用时,Pods可以将其用作环境变量、命令行参数或者存储卷中的配置文件。ConfigMap将你的环境配置信息和。

weixin_58423196的博客 1004

C# 开发实战:深度解析 13.56MHz 射频卡读写应用

本文详细介绍了如何在 C# 环境下开发 13.56MHz 射频卡的读写应用。通过 ACR122U 作为硬件设备,结合 C# 提供的 COM 组件或 SDK,我们能够实现对射频卡的读取与写入功能。在实际开发中,开发者还需要根据具体应用场景选择合适的卡片类型与设备,并注意性能优化和异常处理。随着技术的发展,RFID 技术的应用场景会越来越广泛,开发者可以根据不同需求,灵活扩展读写功能,实现更加智能化和自动化的系统。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1602

Kubernetes(k8s)之Configmap配置管理

Configmap镜像和配置文件的解耦ConfigMap作用ConfigMap应用场景创建ConfigMap的方式1、使用字面值创建2、使用文件创建3、使用目录创建4、编写configmap的yaml文件创建如何使用configmap1、通过环境变量的方式直接传递给pod2、通过在pod的命令行下运行的方式3、作为volume的方式挂载到pod内 镜像和配置文件的解耦 应用部署的一个最佳实践是将应用所需的配置信息与程序进行分离,这样可以使应用程序被更好地复用,通过不同的配置也能实现更灵活的功能。将应用打包为

Tuki来了 1864

【网络教程】Ubuntu有线连接消失,无法联网怎么办!(亲测有效!)

文章目录问题描述解决方案 问题描述 今天打开Ubuntu,突然发现无法连接网络,并且打开设置,发现设置里面的网络已经没有了有线连接,只有VPN设置选项,如图 解决方案 按照下列的代码执行即可! # 关闭网路 service NetworkManager stop # 删除NetworkManager缓存文件 sudo rm /var/lib/NetworkManager/NetworkManager.state # 打开网络 service NetworkManager start 运行完

XiaoqiangClub的博客 1万+

2026年运维工程师常见面试选择题

这篇文章总结了30道Linux运维面试常见问题及解析,涵盖基础命令、系统监控、故障排查、数据库、缓存、容器编排等多个方面。主要内容包括: 基础命令使用:如df查看磁盘、free查看内存、top监控进程等 系统监控与故障排查:负载判断、端口检查、进程管理等 中间件相关:Nginx状态码、MySQL主从复制、Redis缓存问题 容器技术:Docker优势、Kubernetes作用 运维理念:高可用、监控告警、发布策略、备份容灾 工作原则:故障处理优先级、运维工程师核心能力 文章不仅提供标准答案,还解析了各命令的

不务正业的猿 194

Kubernetes中Pod的配置管理ConfigMap

Kubernetes中Pod的配置管理ConfigMap

YIYIYI 1281

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

一、 Kubernetes 配置管理 ConfigMap

应用部署的一个最佳实践是将应用所需的配置信息与程序分离,这样可以使应用程序被更好地复用,通过不同的配置也能实现更灵活的功能。将应用打包为容器镜像后,可以通过环境变量或者外挂文件的方式在创建容器时进行配置注入,但在大规模容器集群的环境中,对多个容器进行不同的配置将变得非常复杂。ConfigMap 是一种 API 对象,用来将非机密性的数据保存到键值对中。使用时,Pods可以将其用作环境变量、命令行参数或者存储卷中的配置文件。ConfigMap 将你的环境配置信息和容器镜像解耦,便于应用配置的修改。从。

m0_71788802的博客 1031

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

K8S(六):Pod的配置管理——ConfigMap使用

一文简要说一下configMap的基本使用方法。

人在江湖 5656

【kubernetes系列】Kubernetes之configMap

工作中,在几乎所有的应用开发中,都会涉及到配置文件的变更,比如服务需要配置MySQL、Redis等相关信息。而业务上线一般要经历开发环境、测试环境、预发布环境只到最终的线上环境,每一个环境一般都需要其独立的配置。如果我们不能很好的管理这些配置文件,运维工作将顿时变的无比的繁琐而且很容易出错。工作中最佳实践是将应用所需的配置信息于程序进行分离,这样可以使得应用程序被更好的复用,如将应用打包为容器镜像后,可以通过环境变量或外挂文件的方式在创建容器时进行配置注入。

margu_168的博客 2399
上一篇: Elasticsearch SQL用法详解
下一篇: kubernetes之ingress及ingress controller
王树民
博客等级 码龄10年 912粉丝 560原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值