18 Dec 2021 cka练习(十三)

2023-10-17 10:34:36 浏览数 (1)

代码语言:javascript复制
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
  name: s1
type: Opaque
stringData:
  name1: tom1
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: mycontainer
    image: quay.io/songleo/nginx
    env:
      - name: MYENV
        valueFrom:
          secretKeyRef:
            name: s1
            key: name1
  restartPolicy: Never
EOF
$ k get secret s1
NAME   TYPE     DATA   AGE
s1     Opaque   1      8s
$ k get po
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          107s
$ k exec nginx -- env | grep MYENV
MYENV=tom1
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm1
data:
  name2: tom2
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx2
spec:
  containers:
  - name: mypod
    image: quay.io/songleo/nginx
    volumeMounts:
    - name: foo
      mountPath: "/also/data"
      readOnly: true
  volumes:
  - name: foo
    configMap:
      name: cm1
EOF
$ k get cm
NAME               DATA   AGE
cm1                1      26s
kube-root-ca.crt   1      7m22s
$ k get cm cm1
NAME   DATA   AGE
cm1    1      31s
$ k get po
NAME     READY   STATUS    RESTARTS   AGE
nginx2   1/1     Running   0          34s
$ k exec nginx2 -- ls /also/data
name2
$ k exec nginx2 -- cat /also/data/name2
tom2

参考

  • cka/ckad应试指南:从docker到kubernetes完全攻略 ch-7

LEo at 00:12

0 人点赞