# 创建pod[root@master ~]# kubectl create -f pod-configmap.yaml
pod/pod-configmap created
# 查看pod[root@master ~]# kubectl get pod pod-configmap -n dev
NAME READY STATUS RESTARTS AGE
pod-configmap 1/1 Running 0 6s
#进入容器[root@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的内容, 容器中的值也会动态更新
# 创建pod[root@master ~]# kubectl create -f pod-secret.yaml
pod/pod-secret created
# 查看pod[root@master ~]# kubectl get pod pod-secret -n dev
NAME READY STATUS RESTARTS AGE
pod-secret 1/1 Running 0 2m28s
# 进入容器,查看secret信息,发现已经自动解码了[root@master ~]# kubectl exec-it pod-secret /bin/sh -n dev
/ # ls /secret/config/
password username
/ # more /secret/config/username
admin
/ # more /secret/config/password
123456
至此,已经实现了利用secret实现了信息的编码。
二、Edge存储
1.KubeEdge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@k8s-master kubeedge]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
edge-1 Ready agent,edge 3d8h v1.23.17-kubeedge-v1.13.4
edge-2 Ready agent,edge 3d7h v1.23.17-kubeedge-v1.13.4
k8s-master Ready control-plane,master 10d v1.23.12
k8s-node1 Ready <none> 10d v1.23.12
[root@k8s-master kubeedge]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
edge-1 Ready agent,edge 3d8h v1.23.17-kubeedge-v1.13.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=edge-1,kubernetes.io/os=linux,node-role.kubernetes.io/agent=,node-role.kubernetes.io/edge=,node-type=edge
edge-2 Ready agent,edge 3d7h v1.23.17-kubeedge-v1.13.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=edge-2,kubernetes.io/os=linux,node-role.kubernetes.io/agent=,node-role.kubernetes.io/edge=,node-type=edge
k8s-master Ready control-plane,master 10d v1.23.12 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=
k8s-node1 Ready <none> 10d v1.23.12 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node1,kubernetes.io/os=linux,node-type=node
#访问nginx# curl 192.168.202.211[root@k8s-master kubeedge]# curl 192.168.202.211
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark;}
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 接下来就可以去host的/root/logs目录下查看存储的文件了[root@edge-1 logs]# pwd
/root/logs
[root@edge-1 logs]# ll
total 8
-rw-r--r--. 1 root root 96 Dec 26 04:57 access.log
-rw-r--r--. 1 root root 510 Dec 26 04:54 error.log
[root@edge-1 logs]# vim access.log
192.168.202.201 - - [25/Dec/2023:20:57:45 +0000] "GET / HTTP/1.1" 200 615 "-""curl/7.29.0""-"# 同样的道理,如果在此目录下创建一个文件,到容器中也是可以看到的
# curl 192.168.202.211[root@k8s-master kubeedge]# curl 192.168.202.211
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark;}
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 通过kubectl logs命令查看指定容器的标准输出# kubectl logs -f volume-emptydir-5dfff4f6c6-rljw5 -c busybox[root@k8s-master kubeedge]# kubectl logs -f volume-emptydir-5dfff4f6c6-rljw5 -c busybox
192.168.202.201 - - [25/Dec/2023:21:14:24 +0000] "GET / HTTP/1.1" 200 615 "-""curl/7.29.0""-"
[root@k8s-master kubeedge]# kubectl apply -f configmap-nginx.yaml
configmap/configmap-nginx created
[root@k8s-master kubeedge]# kubectl get cm
NAME DATA AGE
configmap-nginx 1 19s
kube-root-ca.crt 1 10d
# 查看configmap详情[root@k8s-master kubeedge]# kubectl apply -f configmap-nginx.yaml
configmap/configmap-nginx created
[root@k8s-master kubeedge]# kubectl get cm
NAME DATA AGE
configmap-nginx 1 19s
kube-root-ca.crt 1 10d
[root@k8s-master kubeedge]# kubectl describe cm configmap-nginx
Name: configmap-nginx
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
info:
----
username:admin
password:123456
BinaryData
====
Events: <none>