当前位置: 首页 > news >正文

建设网站商城推广普通话的画

建设网站商城,推广普通话的画,uc浏览网页版进入,wordpress 火车采集文章目录 一、配置存储1.1 ConfigMap1.1.1.基于文件夹的创建方式1.1.2指定文件的创建方式1.1.3 配置文件创建configmap 1.2 Secret1.2.1Secret的应用与Docker仓库 Secret设置1. Kubernetes 中的 Secrets#xff1a;创建 Secret 示例#xff1a;将 Secret 挂载到 Pod 中的示例… 文章目录 一、配置存储1.1 ConfigMap1.1.1.基于文件夹的创建方式1.1.2指定文件的创建方式1.1.3 配置文件创建configmap 1.2 Secret1.2.1Secret的应用与Docker仓库 Secret设置1. Kubernetes 中的 Secrets创建 Secret 示例将 Secret 挂载到 Pod 中的示例2. Docker 仓库中的 Secret在 Kubernetes 中设置 Docker 仓库的 Secret 示例在 Pod 中使用 Docker 仓库的 Secret 示例 1.3SubPath 的使用1.3.1 使用SubPath 1.4ConfigMap的热更新1.5不可变的 Secret 和 ConfigMap 在前面已经提到容器的生命周期可能很短会被频繁地创建和销毁。那么容器在销毁时保存在容器中的数据也会被清除。这种结果对用户来说在某些情况下是不乐意看到的。为了持久化保存容器的数据kubernetes引入了Volume的概念。 Volume是Pod中能够被多个容器访问的共享目录它被定义在Pod上然后被一个Pod里的多个容器挂载到具体的文件目录下kubernetes通过Volume实现同一个Pod中不同容器之间的数据共享以及数据的持久化存储。Volume的生命容器不与Pod中单个容器的生命周期相关当容器终止或者重启时Volume中的数据也不会丢失。 kubernetes的Volume支持多种类型比较常见的有下面几个 简单存储EmptyDir、HostPath、NFS高级存储PV、PVC配置存储ConfigMap、Secret 一、配置存储 1.1 ConfigMap 1.1.1.基于文件夹的创建方式 ConfigMap是一种比较特殊的存储卷它的主要作用是用来存储配置信息的。使用 kubectl create configmap -h 查看示例构建 configmap 对象 [rootk8s-master ~]# mkdir config [rootk8s-master ~]# cd config[rootk8s-master config]# kubectl create configmap -h 创建两个配置文件 [rootk8s-master config]# mkdir test [rootk8s-master config]# cd test/ [rootk8s-master test]# ls [rootk8s-master test]# touch db.properties [rootk8s-master test]# ls db.properties [rootk8s-master test]# vi db.properties usernameroot passwordadmin[rootk8s-master test]# vi redis.propertieshost:127.0.0.1 port:6379 #创建一个名为 test-dir-config 的 ConfigMap其中包含来自指定目录的所有文件 [rootk8s-master config]# kubectl create configmap test-dir-config --from-filetest/ configmap/test-dir-config createdkubectl create configmap: 这是用于在 Kubernetes 中创建 ConfigMap 的命令。test-dir-config: 这是您为新创建的 ConfigMap 指定的名称。–from-filetest/: 这个标志指定了 ConfigMap 的数据来自哪个目录kubectl create configmap: 这是用于在 Kubernetes 中创建 ConfigMap 的命令。 # 获取ConfigMap 列表 [rootk8s-master config]# kubectl get cm NAME DATA AGE kube-root-ca.crt 1 15d test-dir-config 2 103s kube-root-ca.crt: 包含了一个数据项 存储根证书的 ConfigMaptest-dir-config: 包含了两个数据项。这是在之前的操作中创建的 ConfigMap它从 test/ 目录中获取了两个文件的内容。 #查看详细信息 [rootk8s-master config]# kubectl describe cm test-dir-config1.1.2指定文件的创建方式 [rootk8s-master config]# vi application.ymlspring:application:name: test app server:port:8080 [rootk8s-master config]# kubectl create cm spring-boot-test-yaml --from-file/root/config/application.yml configmap/spring-boot-test-yaml created # 获取ConfigMap 列表 [rootk8s-master config]# kubectl get cm NAME DATA AGE kube-root-ca.crt 1 15d spring-boot-test-yaml 1 20s test-dir-config 2 12m [rootk8s-master config]# kubectl describe cm spring-boot-test-yaml 1.1.3 配置文件创建configmap 创建configmap.yaml内容如下 apiVersion: v1 kind: ConfigMap metadata:name: configmapnamespace: dev data:info: |username:adminpassword:123456 接下来使用此配置文件创建configmapp 创建configmap [rootk8s-master config]# kubectl create -f configmap.yaml configmap/configmap created # 查看configmap详情 [rootk8s-master config]# kubectl describe cm configmap -n dev Name: configmap Namespace: dev Labels: none Annotations: noneDatainfo: ---- username:admin password:123456BinaryData Events: none 接下来创建一个pod-configmap.yaml将上面创建的configmap挂载进去 apiVersion: v1 kind: Pod metadata:name: pod-configmapnamespace: dev spec:containers:- name: nginximage: nginx:1.17.1volumeMounts: # 将configmap挂载到目录- name: configmountPath: /configmap/configvolumes: # 引用configmap- name: configconfigMap:name: configmap # 创建pod [rootk8s-master config]# kubectl create -f pod-configmap.yaml pod/pod-configmap created # 查看pod [rootk8s-master config]# kubectl get pod pod-configmap -n dev NAME READY STATUS RESTARTS AGE pod-configmap 1/1 Running 0 15s#进入容器 [rootk8s-master ~]# kubectl exec -it pod-configmap -n dev -- /bin/sh # # cd /configmap/config/ # ls info # more info username:admin password:123456# 可以看到映射已经成功每个configmap都映射成了一个目录 # key---文件 value----文件中的内容 # 此时如果更新configmap的内容, 容器中的值也会动态更新 1.2 Secret 在kubernetes中还存在一种和ConfigMap非常类似的对象称为Secret对象。它主要用于存储敏感信息例如密码、秘钥、证书等等。 1.2.1Secret的应用与Docker仓库 Secret设置 1. Kubernetes 中的 Secrets 在 Kubernetes 中Secrets 可以用于以下目的 存储敏感数据 比如数据库密码、API 密钥等。挂载到 Pod 中 Secrets 可以通过 Volume 挂载到 Pod 中使应用程序能够读取敏感数据。这有助于将敏感信息与应用程序的配置分离开。用于身份验证 在某些情况下Secrets 也可以用于身份验证例如在 Ingress 中配置 TLS 证书。 创建 Secret 示例 1.首先使用base64对数据进行编码 #准备username [rootk8s-master ~]# echo -n admin | base64 YWRtaW4#准备password [rootk8s-master ~]# echo -n 123456 | base64 MTIzNDU2 2.接下来编写secret.yaml并创建Secret apiVersion: v1 kind: Secret metadata:name: secretnamespace: dev type: Opaque data:username: YWRtaW4password: MTIzNDU2 # 创建secret [rootk8s-master config]# kubectl create -f secret.yaml secret/secret created # 查看secret详情 [rootk8s-master config]# kubectl describe secret secret -n dev Name: secret Namespace: dev Labels: none Annotations: noneType: OpaqueDatapassword: 6 bytes username: 5 bytes 3.创建pod-secret.yaml将上面创建的secret挂载进去 apiVersion: v1 kind: Pod metadata:name: pod-secretnamespace: dev spec:containers:- name: nginximage: nginx:1.17.1volumeMounts: # 将secret挂载到目录- name: configmountPath: /secret/configvolumes:- name: configsecret:secretName: secret # 创建pod [rootk8s-master config]# kubectl create -f pod-secret.yaml pod/pod-secret created# 查看pod [rootk8s-master config]# kubectl get pod pod-secret -n dev NAME READY STATUS RESTARTS AGE pod-secret 1/1 Running 0 2m28s# 进入容器查看secret信息发现已经自动解码了 [rootk8s-master config]# kubectl exec -it pod-secret -- /bin/sh -n dev / # ls /secret/config/ password username / # more /secret/config/username admin / # more /secret/config/password 123456 另一种创建方法 kubectl create secret generic my-secret \--from-literalusernamemy-username \--from-literalpasswordmy-password 将 Secret 挂载到 Pod 中的示例 apiVersion: v1 kind: Pod metadata:name: mypod spec:containers:- name: mycontainerimage: myimagevolumeMounts:- name: secret-volumemountPath: /etc/myappvolumes:- name: secret-volumesecret:secretName: my-secret 2. Docker 仓库中的 Secret 在 Docker 仓库中Secrets 通常用于 拉取私有镜像 如果您的 Docker 镜像存储库是私有的您需要将 Docker 仓库的凭据存储在 Kubernetes 中的 Secret 中以便 Pods 能够拉取镜像。 在 Kubernetes 中设置 Docker 仓库的 Secret 示例 kubectl create secret docker-registry my-docker-secret \--docker-servermy-docker-registry.com \--docker-usernamemy-username \--docker-passwordmy-password \--docker-emailmy-emailexample.com在 Pod 中使用 Docker 仓库的 Secret 示例 apiVersion: v1 kind: Pod metadata:name: mypod spec:containers:- name: mycontainerimage: my-docker-registry.com/myimage:latestimagePullSecrets:- name: my-docker-secret 这将使 Kubernetes 能够使用 my-docker-secret 中的凭据拉取 my-docker-registry.com/myimage:latest 这个私有 Docker 镜像 1.3SubPath 的使用 使用 ConfigMap 或 Secret 挂载到目录的时候会将容器中源目录给覆盖掉此时我们可能只想覆盖目录中的某一个文件但是这样的操作会覆盖整个文件因此需要使用到 SubPath配置方式 定义 volumes 时需要增加 items 属性配置 key 和 path且 path 的值不能从 / 开始在容器内的 volumeMounts 中增加 subPath 属性该值与 volumes 中 items.path 的值相同 containers: ...... volumeMounts: - mountPath: /etc/nginx/nginx.conf # 挂载到哪里 name: config-volume # 使用哪个 configmap 或 secret subPath: etc/nginx/nginx.conf # 与 volumes.[0].items.path 相同 volumes: - configMap: name: nginx-conf # configMap 名字 items: # subPath 配置 key: nginx.conf # configMap 中的文件名 path: etc/nginx/nginx.conf # subPath 路径[rootk8s-master etc]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-85b98978db-mkp29 1/1 Running 2 (3d3h ago) 12d nginx-deploy-c4986b7f-8tplt 1/1 Running 2 (3d3h ago) 6d6h nginx-deploy-c4986b7f-qltv6 1/1 Running 2 (3d3h ago) 6d6h [rootk8s-master etc]# kubectl exec -it nginx-deploy-c4986b7f-8tplt -- sh # cd /etc # cd nginx # ls conf.d fastcgi_params koi-utf koi-win mime.types nginx.conf scgi_params uwsgi_params win-utf # cat nginx.conf user nginx; worker_processes 1;error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;events {worker_connections 1024; }http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;access_log /var/log/nginx/access.log main;sendfile on;#tcp_nopush on;keepalive_timeout 65;#gzip on;include /etc/nginx/conf.d/*.conf; } #复制配置信息 退出容器 # exit #创建nginx.conf文件 [rootk8s-master config]# vi nginx-conf [rootk8s-master config]# ls nginx-conf[rootk8s-master config]# kubectl create configmap nginx-conf-cm --from-file./nginx-conf configmap/nginx-conf-cm created [rootk8s-master config]# kubectl describe cm nginx-conf-cmName: nginx-conf-cm Namespace: default Labels: none Annotations: noneDatanginx-conf: ---- user nginx; worker_processes 1;error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;events {worker_connections 1024; }http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;access_log /var/log/nginx/access.log main;sendfile on;#tcp_nopush on;keepalive_timeout 65;#gzip on;include /etc/nginx/conf.d/*.conf; }BinaryData Events: none 存储的内容就是nginx-conf这个文件 [rootk8s-master config]# kubectl edit deploy nginx-deployvolumeMounts: # 挂在数据卷- name: nginx-conf # 数据卷的名称mountPath: /etc/nginx # 挂载的路径volumes: # 数据卷定义- name: nginx-conf # 数据卷的名称configMap: # 数据卷类型为 configmapname: nginx-conf-cm #configmap名字items: # 要将 configmap中哪些数据挂在尽力啊- key: nginx-conf # 指定挂在哪个keypath: nginx.conf # 挂在后该key重命名什么名字 [rootk8s-master config]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-85b98978db-mkp29 1/1 Running 2 (3d3h ago) 12d nginx-deploy-7c6975968-t5w5b 0/1 CrashLoopBackOff 4 (62s ago) 2m37s [rootk8s-master config]# kubectl edit deploy nginx-deploy deployment.apps/nginx-deploy edited # 在name: nginx后面加入command: [/bin/sh, -c,nginx daemon off;sleep 3600] [rootk8s-master config]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-deploy-55f7b46d59-lp5px 1/1 Running 0 22s nginx-deploy-55f7b46d59-wrfjm 1/1 Running 0 20s [rootk8s-master config]# kubectl exec -it nginx-deploy-55f7b46d59-lp5px -- sh # cd /etc/nginx # ls nginx.conf进入容器后发现原来的一堆配置文件都不见了得出结果:使用 ConfigMap 或 Secret 挂载到目录的时候会将容器中源目录给覆盖掉.此时我们可能只想覆盖目录中的某一个文件但是这样的操作会覆盖整个文件因此需要使用到 SubPath 1.3.1 使用SubPath [rootk8s-master config]# kubectl edit deploy nginx-deployvolumeMounts:- mountPath: /etc/nginx/nginx.confname: nginx-confsubPath: etc/nginx/nginx.confvolumes:- configMap:defaultMode: 420items:- key: nginx-confpath: etc/nginx/nginx.confname: nginx-conf-cmname: nginx-conf [rootk8s-master config]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-85b98978db-mkp29 1/1 Running 2 (3d20h ago) 12d nginx-deploy-5588c8bc86-bhj9l 1/1 Running 0 35s nginx-deploy-5588c8bc86-ltxvs 1/1 Running 0 34s #进入容器 [rootk8s-master config]# kubectl exec -it nginx-deploy-5588c8bc86-bhj9l -- sh # # cd /etc/nginx # ls conf.d fastcgi_params koi-utf koi-win mime.types nginx.conf scgi_params uwsgi_params win-utf 配置了subPath后进入容器后发现 原来那些文件没有被覆盖掉了这样就解决了加载配置覆盖原目录的问题。 1.4ConfigMap的热更新 我们通常会将项目的配置文件作为 configmap 然后挂载到 pod那么如果更新 configmap 中的配置会不会更新到 pod 中呢这得分成几种情况默认方式会更新更新周期是更新时间 缓存时间subPath不会更新变量形式如果 pod 中的一个变量是从 configmap 或 secret 中得到同样也是不会更新的对于 subPath 的方式我们可以取消 subPath 的使用将配置文件挂载到一个不存在的目录避免目录的覆盖然后再利用软连接的形式将该文件链接到目标位置但是如果目标位置原本就有文件可能无法创建软链接此时可以基于前面讲过的 postStart 操作执行删除命令将默认的文件删除即可 通过 edit 命令直接修改 configmap通过 replace 替换 由于 configmap 我们创建通常都是基于文件创建并不会编写 yaml 配置文件因此修改时我们也是直接修改配置文件而 replace 是没有 --from-file 参数的因此无法实现基于源配置文件的替换此时我们可以利用下方的命令实现# 该命令的重点在于 --dry-run 参数该参数的意思打印 yaml 文件但不会将该文件发送给 apiserver再结合 -oyaml 输出 yaml 文件就可以得到一个配置好但是没有发给 apiserver 的文件然后再结合 replace 监听控制台输出得到 yaml 数据即可实现替换kubectl create cm --from-filenginx.conf --dry-run -o yaml | kubectl replace -f- #查看当前的 ConfigMap [rootk8s-master config]# kubectl get cm -n dev NAME DATA AGE configmap 1 3d19h[rootk8s-master config]# ls application.yml file1.txt nginx-conf nginx-pod-configmap.yaml secret.yaml configmap.yaml file2.txt nginx.conf pod-secret.yaml test #修改 ConfigMap 数据 [rootk8s-master config]# vi configmap.yamlusername:AAApassword:BBB#更新 ConfigMap 读取 configmap.yaml 文件中的数据 #并使用 kubectl replace 将其更新到 configmap ConfigMap 中 [rootk8s-master config]# kubectl create cm configmap -n dev --from-fileconfigmap.yaml --dry-runclient -o yaml | kubectl replace -f- configmap/configmap replaced[rootk8s-master config]# kubectl get pod pod-configmap -n dev NAME READY STATUS RESTARTS AGE pod-configmap 1/1 Running 0 15s# 验证更新是否传递到 Pod [rootk8s-master config]# kubectl exec -it pod-configmap -n dev -- /bin/sh # cd /configmap/config/ # ls configmap.yaml # cat configmap.yaml apiVersion: v1 kind: ConfigMap metadata:name: configmapnamespace: dev data:info: |username:AAApassword:BBB 确保挂载路径与 ConfigMap 中定义的路径一致然后查看文件内容是否更新为新的用户名和密码。这样就成功地使用 kubectl 命令更新了 ConfigMap 并确保更新成功地传递到相关的 Pod 中 1.5不可变的 Secret 和 ConfigMap **对于一些敏感服务的配置文件在线上有时是不允许修改的此时在配置 configmap 时可以设置 immutable: true 来禁止修改.**这个配置项会锁定 ConfigMap使其变得只读防止运维人员或其他用户无意中修改关键配置
http://www.pierceye.com/news/729722/

相关文章:

  • 网站备案 历史wordpress货币插件
  • 如何做自助搜券网站佛山顺德专业做网站
  • 义乌网站制作多少钱工会网站建设
  • 六安高端网站建设公司开网店的流程步骤
  • 网站被墙301怎么做展馆展厅设计效果图
  • 唐山市城市建设规划局网站大兴做网站公司
  • 陕西做网站的公司地址克拉玛依市住房和建设局网站
  • 做电影网站 广告收入怎么知道网站被k
  • 开发企业网站费用深圳宝安seo
  • 算命公司网站建设制作开发方案教育培训机构招生网站建设
  • 织梦做网站被告全椒网站建设
  • 安卓网站开发平台互联网工具型网站
  • 如何建设国外的网站联盟营销网站有哪些
  • 微信怎么创建微信公众号seo应该如何做
  • 北京php网站制作网站群建设思路
  • 企业建设网站的必要性小程序平台介绍怎么写
  • 网站界面设计应该遵循的原则贵州省住房和城乡建设厅网站报名网
  • 南昌建设医院官方网站国外做外链常用的网站
  • 淘宝店采用哪些方法做网站推广专门做网站的软件
  • 网站的ftp怎么查中国视觉设计网
  • 商城网站流量wordpress安装后做什么
  • 自己建网站要花多少钱wordpress采集发布接口
  • 个人网站做交易类的赚钱吗达人室内设计网论坛
  • 网站后台使用培训怎么样做微信公众号
  • 北京望京企业网站建设八佰yy影视
  • 在百度上做个网站需要多少钱创易网络
  • 网站建设神器帮人做网站犯法
  • 企业网站的特点是小程序开发文档微信小程序
  • 哈尔滨 建网站mvc做的网站如何发布访问
  • 江苏盐城网站开发百度快照首页