欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

K8s?ConfigMaps與Secret實(shí)現(xiàn)配置分離過程

 更新時(shí)間:2025年08月14日 09:35:20   作者:大新屋  
本文介紹Kubernetes中ConfigMaps和Secret的創(chuàng)建方式及應(yīng)用,涵蓋文件、literal、YAML方法,強(qiáng)調(diào)命名空間匹配與鍵名大小寫一致性,Secret類型如Opaque、dockerconfigjson用于加密配置,熱更新需注意envFrom等參數(shù)限制
  • 提示:kubernetes 官方ConfigMaps文檔說明:https://kubernetes.io/docs/concepts/configuration/configmap/
  • 提示:kubernetes 官方Secret文檔說明:https://kubernetes.io/docs/concepts/configuration/secret/
  • 提示: ConfigMap和Secret引用Key必須存在,ConfigMaps主要用于明文的配置信息,Secret主要用于需要加密的配置信息,ConfigMap和Secret 配置信息不建議過多
  • 提示:envFrom、valueFrom參數(shù)無法熱更新環(huán)境變量,使用subrsth參數(shù)是無法熱更新的
  • 提示:ConfigMap支持的數(shù)據(jù)data和binaryData兩種數(shù)據(jù)對象,data是UTF-8字符集,binaryData是二進(jìn)制數(shù)據(jù)(base64編碼的字符串)

一、ConfigMaps創(chuàng)建形式

1、基于文件創(chuàng)建ConfigMaps

### 創(chuàng)建ConfigMaps 配置信息
mkdir -p /data/yaml/configmap/conf
cat > /data/yaml/configmap/conf/nginx01.config << 'EOF'
nginx=1.24
user=nginx01
passwd=123456
EOF
cat > /data/yaml/configmap/conf/nginx02.config  << 'EOF'
nginx=1.26
user=nginx02
password=123456
EOF

### 基于目錄創(chuàng)建ConfigMaps
kubectl create configmap nginx-cm01 --namespace=default --from-file=/data/yaml/configmap/conf

### 基于單個(gè)文件創(chuàng)建ConfigMaps
kubectl create configmap nginx-cm02 --namespace=default --from-file=/data/yaml/configmap/conf/nginx01.config

### 基于多個(gè)文件創(chuàng)建ConfigMaps
kubectl create configmap nginx-cm03 --namespace=default --from-file=/data/yaml/configmap/conf/nginx01.config --from-file=/data/yaml/configmap/conf/nginx02.config

### 自定義ConfigMaps data名稱
kubectl create configmap nginx-cm04 --namespace=default --from-file=nginx-1.24=/data/yaml/configmap/conf/nginx01.config

### 查看ConfigMaps
kubectl get configmap -n default
kubectl get cm -n default
kubectl get configmap nginx-cm01 -n default -oyaml
kubectl get cm nginx-cm01 -n default -oyaml

### 刪除ConfigMaps
kubectl delete cm nginx-cm01 nginx-cm02 nginx-cm03 nginx-cm04 -n default

2、基于文件導(dǎo)入env創(chuàng)建ConfigMaps

### 創(chuàng)建ConfigMaps 配置信息
mkdir -p /data/yaml/configmap/conf
cat > /data/yaml/configmap/conf/redis01.config << 'EOF'
redis_version1=3.6
user1=redis01
passwd1=123456
EOF
cat > /data/yaml/configmap/conf/redis02.config << 'EOF'
redis_version2=4.6
user2=redis02
passwd2=123456
EOF

### 基于單個(gè)env文件創(chuàng)建ConfigMaps
kubectl create cm redis-cm01 --namespace=default --from-env-file=/data/yaml/configmap/conf/redis01.config

### 基于多個(gè)env文件創(chuàng)建ConfigMaps
kubectl create configmap redis-cm02 --namespace=default --from-env-file=/data/yaml/configmap/conf/redis01.config --from-env-file=/data/yaml/configmap/conf/redis02.config

### 查看ConfigMaps
kubectl get cm -n default
kubectl get cm redis-cm01 -n default –oyaml

### 刪除ConfigMaps
kubectl delete cm redis-cm01 redis-cm02 -n default

3、基于literal創(chuàng)建ConfigMaps

kubectl create cm nginx-literal -n default --from-literal=nginx_version=1.26 --from-literal=user=nginx01 --from-literal=password=123456
kubectl get cm -n default
kubectl get cm nginx-literal -n default -oyaml

4、基于yaml文件創(chuàng)建ConfigMaps

cat > /data/yaml/configmap/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: game-demo
  namespace: default
data:
  player_initial_lives: "3"
  ui_properties_file_name: "user-interface.properties"

  game.properties: |
    enemy.types=aliens,monsters
    player.maximum-lives=5

  user-interface.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
EOF

kubectl create -f /data/yaml/configmap/configmap.yaml

### 查看ConfigMaps
kubectl get cm -n default
kubectl get cm game-demo -n default –oyaml

### 刪除ConfigMaps
kubectl delete -f /data/yaml/configmap/configmap.yaml

二、Deployment應(yīng)用ConfigMaps

注意:

.spec.containers.env.name參數(shù)值名稱(大寫字母)與.sepc.containers.env.valueFrom. configMapKeyRef.key參數(shù)值名稱一樣(小寫字母),Deployment與ConfigMaps必須在同一個(gè)namespace命名空間下。

1、基于env.valueFrom單個(gè)環(huán)境變量創(chuàng)建ConfigMaps

### 創(chuàng)建ConfigMaps
cat > /data/yaml/configmap/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: game-demo
  namespace: default
data:
  player_initial_lives: "3"
  ui_properties_file_name: "user-interface.properties"

  game.properties: |
    enemy.types=aliens,monsters
    player.maximum-lives=5

  user-interface.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
EOF

kubectl create -f /data/yaml/configmap/configmap.yaml

### 創(chuàng)建Deployment并應(yīng)用ConfigMap變量
cat > /data/yaml/configmap/nginx-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-deploy
  name: nginx-deploy
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-deploy
  template:
    metadata:
      labels:
        app: nginx-deploy
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/nginx:1.26
        name: nginx
        env:
        - name: NginxVersion
          value: "1.26"
        - name: PLAYER_INITIAL_LIVES
          valueFrom:
            configMapKeyRef:
              name: game-demo
              key: player_initial_lives
        - name: UI_PROPERTIES_FILE_NAME
          valueFrom:
            configMapKeyRef:
              name: game-demo
              key: ui_properties_file_name
EOF

kubectl create -f /data/yaml/configmap/nginx-deploy.yaml

### 查看ConfigMap和Deployment
kubectl get cm -n default
kubectl get cm game-demo -n default -oyaml
kubectl get deploy -n default -owide
kubectl get pod -n default
kubectl get deploy -n default -oyaml

### 進(jìn)入Pod容器內(nèi)查看環(huán)境變量
kubectl exec -it nginx-deploy-55c4bcc476-qrmcr -- bash
env
echo $NginxVersion
echo $PLAYER_INITIAL_LIVES
echo $UI_PROPERTIES_FILE_NAME

2、基于envFrom批量生成環(huán)境變量創(chuàng)建ConfigMaps

### 創(chuàng)建ConfigMaps
cat > /data/yaml/configmap/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: game-demo
  namespace: default
data:
  player_initial_lives: "3"
  ui_properties_file_name: "user-interface.properties"

  game.properties: |
    enemy.types=aliens,monsters
    player.maximum-lives=5

  user-interface.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
EOF

kubectl create -f /data/yaml/configmap/configmap.yaml

### ### 創(chuàng)建Deployment并應(yīng)用ConfigMap變量(.template.spce.containers.envFrom.prefix參數(shù)是固定批量導(dǎo)入的每個(gè)變量都有一個(gè)自定義前綴,用于區(qū)分變量來源)
cat > /data/yaml/configmap/redis-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis-deploy
  name: redis-deploy
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-pod
  template:
    metadata:
      labels:
        app: redis-pod
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/redis:6.2.16
        name: redis
        envFrom:
        - configMapRef:
             name: game-demo
          prefix: GAME-DEMO_
EOF

kubectl create -f /data/yaml/configmap/redis-deploy.yaml

### 查看ConfigMap和Deployment
kubectl get cm -n default
kubectl get cm game-demo -n default -oyaml
kubectl get deploy -n default -owide
kubectl get pod -n default
kubectl get deploy -n default -oyaml

### 查看Pod容器環(huán)境變量ENV
kubectl exec -n default redis-deploy-f74fd777b-zx97k -- env

3、基于文件形式掛載ConfigMaps

### 創(chuàng)建ConfigMaps
cat > /data/yaml/configmap/nginx-configmaps.yaml << 'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-configmap	
  namespace: default
data:
  nginx.conf: |
    user  nginx;
    worker_processes  auto;
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;

    events {
        worker_connections  4096;
    }

    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;
        keepalive_timeout  65;
        include /etc/nginx/conf.d/*.conf;
    }
EOF

kubectl create -f  /data/yaml/configmap/nginx-configmaps.yaml

### 創(chuàng)建Deployment并應(yīng)用ConfigMaps
### .spec.containers.volumeMounts.subPath參數(shù)允許Pod容器內(nèi)部將卷掛載到特定子目錄或者掛載特定根目錄文件,而不是直接掛載到卷的根目錄
cat > /data/yaml/configmap/nginx-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-deploy
  name: nginx-deploy
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-pod
  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
        - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/nginx:1.26
          name: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - name: nginx-cm
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
      volumes:
        - name: nginx-cm
          configMap:
            name: nginx-configmap
EOF

kubectl create -f  /data/yaml/configmap/nginx-deploy.yaml

### 查看ConfigMap和Deployment
kubectl get cm -n default
kubectl get cm nginx-configmap -n default -oyaml
kubectl get deploy -n default -owide
kubectl get pod -n default
kubectl get deploy -n default -oyaml

### 查看Pod容器生成的配置文件nginx.conf
kubectl exec nginx-deploy-758875fd9d-pvh8x -- cat /etc/nginx/nginx.conf

三、Secret創(chuàng)建形式

1、Secret常用類型

  • Opaque【常用】:通用型Secret,默認(rèn)類型
  • kubernetes.io/service-account-token:作用于ServiceAccount,包含一個(gè)令牌,用于標(biāo)識API服務(wù)賬戶
  • kubernetes.io/dockerconfigison【常用】:下載私有倉庫鏡像使用的Secret,和宿主風(fēng)的/root/.docker/config.ison一致,宿主機(jī)登錄后即可產(chǎn)生該文件
  • kubernetes.io/basic-auth:用于使用基本認(rèn)證(賬號密碼)的secret,可以使用Opaque取代
  • kubernetes.io/ssh-auth:用于存儲(chǔ)ssh密鑰的Secret
  • kubernetes.io/tls【常用】:用于存儲(chǔ)HTTPS域名證書文件的Secret,可以被Ingress使用
  • bootstrap.kubernetes.io/token:一種簡單的bearer token,用于創(chuàng)建新集群或?qū)⑿鹿?jié)點(diǎn)添加到現(xiàn)有集群,在集群安裝時(shí)可用于自動(dòng)頒發(fā)集群的證書

2、基于文件創(chuàng)建Secret

### ### 創(chuàng)建Secret 配置信息
mkdir -p /data/yaml/secret/conf
cat > /data/yaml/secret/conf/username << 'EOF'
admin
EOF
cat > /data/yaml/secret/conf/password  << 'EOF'
123456
EOF

### 基于文件創(chuàng)建Secret,其中g(shù)eneric是Secret Opaque類型
kubectl create secret generic db-user-pass -n default --from-file=/data/yaml/secret/conf/username --from-file=/data/yaml/secret/conf/password

### 查看Secret,username和password內(nèi)容顯示已經(jīng)過軟加密處理
kubectl get secret -n default
kubectl get secret db-user-pass -n default -oyaml

### 通過以下命令以明文方式顯示username和password的加密內(nèi)容
echo "YWRtaW4K" | base64 -d            
echo "MTIzNDU2Cg==" | base64 -d

### 刪除Secret
kubectl delete secret db-user-pass -n defalut

3、基于literal創(chuàng)建Secret

kubectl create secret generic use-pass-literal -n default --from-literal=username=admin --from-literal=password='123456

kubectl get secret -n default
kubectl get secret use-pass-literal -n default -oyaml

kubectl delete secret use-pass-literal -n default

4、基于yaml文件創(chuàng)建Secret

### 創(chuàng)建Secret(yaml文件密文顯示,創(chuàng)建后Secret是密文)
echo -n 'admin' | base64 
echo -n '123456' | base64

cat > /data/yaml/secret/secret-once.yaml <<'EOF'
apiVersion: v1
kind: Secret
metadata:
  name: secret-once
type: Opaque
data:
  username: YWRtaW4=
  password: MTIzNDU2
EOF

kubectl create -f /data/yaml/secret/secret-once.yaml
kubectl get secret -n default
kubectl get secret secret-once -n default -oyaml

### 創(chuàng)建Secret(yaml文件明文顯示,創(chuàng)建后Secret是密文)
cat > /data/yaml/secret/secret-twice.yaml <<'EOF'
apiVersion: v1
kind: Secret
metadata:
  name: secret-twice
type: Opaque
stringData:
  username: admin
  password: '123456'
EOF

kubectl create -f /data/yaml/secret/secret-twice.yaml
kubectl get secret -n default
kubectl get secret secret-twice -n default -oyaml

四、Deployment應(yīng)用Secret

1、創(chuàng)建Secret(Secret類型:kubernetes.io/dockerconfigison)

使用場景:使用Secret拉取需要認(rèn)證登錄的私有倉庫鏡像,registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7 這個(gè)鏡像源是作者登錄阿里云申請創(chuàng)建的私有倉庫并設(shè)置需要認(rèn)證登錄才可以拉取

### 創(chuàng)建Deployment并應(yīng)用Secret
cat > /data/yaml/secret/mysql-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mysql-deploy
  name: mysql-deploy
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-pod
  template:
    metadata:
      labels:
        app: mysql-pod
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        ports:
        - containerPort: 3306
EOF

kubectl create -f /data/yaml/secret/mysql-deploy.yaml

### 查看Pod狀態(tài)顯示ImagePullBackOff鏡像拉取失敗
kubectl get pods -n default

### 查看Pod描述信息, 
kubectl describe pods -n default mysql-deploy-8678f9bb6c-428ds
### 以下錯(cuò)誤提示說明拉取registry.cn-shenzhen.aliyuncs.com/dockerghost/alpine:latest鏡像失敗,需要授權(quán)才能拉取
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  87s                default-scheduler  Successfully assigned default/mysql-deploy-8678f9bb6c-428ds to k8s-node03
  Normal   BackOff    21s (x5 over 85s)  kubelet            Back-off pulling image "registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7"
  Warning  Failed     21s (x5 over 85s)  kubelet            Error: ImagePullBackOff
  Normal   Pulling    7s (x4 over 86s)   kubelet            Pulling image "registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7"
  Warning  Failed     7s (x4 over 86s)   kubelet            Failed to pull image "registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7": failed to pull and unpack image "registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7": failed to resolve reference "registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

### 基于命令方式創(chuàng)建docker-registry類型的Secret,自定義的Secret名稱aliyunregistry
kubectl create secret -n default docker-registry aliyunregistry --docker-username=sys1873515692 --docker-password='yes#123' --docker-email=1873515692@qq.com --docker-server=registry.cn-shenzhen.aliyuncs.com

### 基于yaml文件創(chuàng)建docker-registry類型的Secret,自定義的Secret名稱aliyunregistry
kubectl create secret -n default docker-registry aliyunregistry --docker-username=sys1873515692 --docker-password='yes#123' --docker-email=1873515692@qq.com --docker-server=registry.cn-shenzhen.aliyuncs.com --dry-run=client -oyaml > /data/yaml/secret/mysql-secret.yaml

cat >  /data/yaml/secret/mysql-secret.yaml << 'EOF'
apiVersion: v1
data:
  .dockerconfigjson: eyJhdXRocyI6eyJyZWdpc3RyeS5jbi1zaGVuemhlbi5hbGl5dW5jcy5jb20iOnsidXNlcm5hbWUiOiJzeXMxODczNTE1NjkyIiwicGFzc3dvcmQiOiJ5ZXMjMTIzIiwiZW1haWwiOiIxODczNTE1NjkyQHFxLmNvbSIsImF1dGgiOiJjM2x6TVRnM016VXhOVFk1TWpwNVpYTWpNVEl6In19fQ==
kind: Secret
metadata:
  creationTimestamp: null
  name: aliyunregistry
  namespace: default
type: kubernetes.io/dockerconfigjson
EOF

kubectl create -f /data/yaml/secret/mysql-secret.yaml
kubectl get secret -n default
kubectl get secret aliyunregistry -n default -oyaml

### 修改Deployment yaml文件添加.spec.imagePullSecrets參數(shù)加載已創(chuàng)建的Secret(aliyunregistry)并重新應(yīng)用加載
cat > /data/yaml/alpine-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mysql-deploy
  name: mysql-deploy
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-pod
  template:
    metadata:
      labels:
        app: mysql-pod
    spec:
      imagePullSecrets:
      - name: aliyunregistry
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        ports:
        - containerPort: 3306
EOF

kubectl apply -f /data/yaml/secret/mysql-deploy.yaml

### 查看Pod已正常創(chuàng)建
kubectl get deploy -n default
kubectl get pods -n default

2、創(chuàng)建Secret(Secret類型:kubernetes.io/tls)

使用場景:使用Secret管理HTTPS證書,通過Ingress Controller調(diào)用Service和Secret,訪問HTTPS Nginx服務(wù)

### 生成SSL證書
mkdir -p /data/yaml/secret/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout=/data/yaml/secret/ssl/tls.key -out=/data/yaml/secret/ssl/tls.crt -subj "/CN=test.com"

### 創(chuàng)建Secret類型:kubernetes.io/tls
kubectl create secret tls nginx-secret-tls -n default --key=/data/yaml/secret/ssl/tls.key --cert=/data/yaml/secret/ssl/tls.crt

### 查看Secret
kubectl get secret -n default
kubectl get secret nginx-secret-tls -n default -oyaml

### 創(chuàng)建Deployment并應(yīng)用Secret
cat > /data/yaml/secret/nginx-deploy.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-deploy
  name: nginx-deploy
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-pod
  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/dockerghost/nginx:1.26
        name: nginx
        ports:
        - containerPort: 80
EOF

kubectl create -f /data/yaml/secret/nginx-deploy.yaml
kubectl get pods -n default

### 創(chuàng)建Service
cat > /data/yaml/secret/nginx-service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-service
  name: nginx-service
  namespace: default
spec:
  selector:
    app: nginx-pod
  type: ClusterIP
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
EOF

kubectl create -f /data/yaml/secret/nginx-service.yaml
kubectl get services -n default
curl http://10.96.17.21

### 創(chuàng)建Ingress
### 注意:需要K8s集群安裝Ingress Controller才能配置Ingress使用,并且Deployment、Secret、Ingress都要在同一個(gè)namespace命名空間下
cat > /data/yaml/secret/nginx-ingress.yaml << 'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: nginx.test.com
    http:
      paths:
      - backend:
          service:
            name: nginx-service
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - nginx.test.com
    secretName: nginx-secret-tls
EOF

kubectl create -f /data/yaml/secret/nginx-ingress.yaml
kubectl get ingress -n default

### 客戶端的hosts文件需要解析,解析填寫 172.20.235.204   nginx.test.com,客戶端打開瀏覽器訪問 https://nginx.test.com

五、ConfigMap&Secret熱更新

方法一:使用kubectl edit命令方式

###  ConfigMap使用kubectl edit configmap
kubectl edit configmap nginx-configmap

### Secret使用kubectl edit secret
kubectl edit secret nginx-secret

方法二:修改yaml文件配置方式

kubectl replace -f /data/yaml/configmap/nginx-configmap.yaml

方法三:命令方式更新已創(chuàng)建ConfigMap&Secret

kubectl create configmap nginx-configmap --from-file=/data/yaml/configmap/nginx.conf --dry-run=client -oyaml | kubectl replace -f -

六、禁止修改ConfigMap&Secret配置

### 創(chuàng)建ConfigMap,添加immutable參數(shù)設(shè)置為true,可以使用ConfigMap和Secret配置不可以通過kubectl edit進(jìn)行修改
cat > /data/yaml/configmap/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: game-demo
  namespace: default
data:
  player_initial_lives: "3"
  ui_properties_file_name: "user-interface.properties"
  game.properties: |
    enemy.types=aliens,monsters
    player.maximum-lives=5    
  user-interface.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
immutable: true
EOF

kubectl create -f /data/yaml/configmap/configmap.yaml
kubectl get configmap -n default
kubectl get configmap game-demo -oyaml -n default

### 使用kubectl edit 修改configmap無效
kubectl edit configmap game-dem -n default
kubectl get configmap game-demo -oyaml -n default

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Kubernetes k8s configmap 容器技術(shù)解析

    Kubernetes k8s configmap 容器技術(shù)解析

    這篇文章主要為大家介紹了k8s configmap 容器技術(shù)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • k8s控制deamonset中pod數(shù)量的方法

    k8s控制deamonset中pod數(shù)量的方法

    DaemonSet是Kubernetes中用于確保每個(gè)節(jié)點(diǎn)運(yùn)行一個(gè)Pod副本的控制器,常用于運(yùn)行集群守護(hù)進(jìn)程,通過節(jié)點(diǎn)選擇器、節(jié)點(diǎn)親和性、容忍度和更新策略,可以精確控制Pod的數(shù)量和調(diào)度,本文介紹k8s控制deamonset中pod數(shù)量的方法,感興趣的朋友一起看看吧
    2025-01-01
  • K8s準(zhǔn)入控制Admission?Controller深入介紹

    K8s準(zhǔn)入控制Admission?Controller深入介紹

    本篇我們將聚焦于?kube-apiserver?請求處理過程中一個(gè)很重要的部分?--?準(zhǔn)入控制器(Admission?Controller)深入講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-04-04
  • 從小飯館客流量變大論云原生負(fù)載均衡

    從小飯館客流量變大論云原生負(fù)載均衡

    這篇文章主要為大家介紹了從小飯館客流量變大來討論云原生負(fù)載均衡,為大家做出更生動(dòng)易懂的云原生解釋說明有需要的朋友可以借鑒參考下
    2022-03-03
  • Rainbond調(diào)用Vue?React項(xiàng)目的后端接口

    Rainbond調(diào)用Vue?React項(xiàng)目的后端接口

    這篇文章主要為大家介紹了Rainbond調(diào)用Vue?React項(xiàng)目的后端接口問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • Rainbond應(yīng)用分享與發(fā)布官方文檔說明

    Rainbond應(yīng)用分享與發(fā)布官方文檔說明

    這篇文章主要為大家介紹了Rainbond應(yīng)用分享與發(fā)布的官方文檔說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • K8S命令如何查看日志

    K8S命令如何查看日志

    文章內(nèi)容總結(jié):K8S命令查看日志,列出所有節(jié)點(diǎn)、切換節(jié)點(diǎn)、查看容器日志及部分日志內(nèi)容,個(gè)人經(jīng)驗(yàn)分享,希望對大家有所幫助
    2024-11-11
  • 在?k8s?中部署Jenkins的實(shí)踐指南(最新推薦)

    在?k8s?中部署Jenkins的實(shí)踐指南(最新推薦)

    本文介紹了在Kubernetes(K8s)中部署Jenkins的方法和步驟,包括準(zhǔn)備K8s集群、選擇Jenkins鏡像、創(chuàng)建存儲(chǔ)資源、賬號授權(quán)、部署Jenkins、創(chuàng)建Service以及訪問測試,Jenkins在K8s中的部署可以實(shí)現(xiàn)動(dòng)態(tài)資源管理、提高可靠性和容錯(cuò)能力、快速響應(yīng)變化和統(tǒng)一環(huán)境等優(yōu)勢
    2025-03-03
  • K8S?prometheus?operator監(jiān)控工作原理介紹

    K8S?prometheus?operator監(jiān)控工作原理介紹

    這篇文章主要為大家介紹了K8S?prometheus?operator監(jiān)控工作原理介紹,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • DeepSeek-R1 云環(huán)境搭建部署流程

    DeepSeek-R1 云環(huán)境搭建部署流程

    本文主要介紹了DeepSeek-R1 云環(huán)境搭建部署流程,包括注冊、選擇合適的服務(wù)器配置、部署DeepSeek模型及通過UI界面和SSH連接進(jìn)行操作,感興趣的可以了解一下
    2025-02-02

最新評論