https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/
目标:使用在线终端开启一个 Kubernetes 集群。
https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/
minikube version
minikube start
kubectl version
kubectl cluster-info
kubectl get nodes
目标:使用 kubectl 在 Kubernetes 上部署第一个应用
https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/
Deployment作为Pod的控制器,可以对Pod进行创建、滚动升级等常见操作。
kubectl get nodes
kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
kubectl get deployments
echo -e "\n\n\n\e[92mStarting Proxy. After starting it will not output a response. Please click the first Terminal Tab\n";
kubectl proxy
curl http://localhost:8001/version
If Port 8001 is not accessible, ensure that the kubectl proxy started above is running.
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/
https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/explore/explore-intro/
目的:对已部署的应用故障排除。
最常见的操作可以使用以下 kubectl 命令完成:
kubectl get - 列出资源
kubectl describe - 显示有关资源的详细信息
kubectl logs - 打印 pod 和其中容器的日志
kubectl exec - 在 pod 中的容器上执行命令
kubectl get nodes
kubectl describe pods
kubectl logs $POD_NAME
kubectl exec $POD_NAME -- env
kubectl exec -ti $POD_NAME -- bash
cat server.js
exit
目标:在 Kubernetes 集群外用 Service 暴露应用
https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/expose/expose-intro/
尽管每个 Pod 都有一个唯一的 IP 地址,但是如果没有 Service ,这些 IP 不会暴露在集群外部。Service 允许您的应用程序接收流量。Service 也可以用在 ServiceSpec 标记type的方式暴露。
1)ClusterIP (默认) - 在集群的内部 IP 上公开 Service 。这种类型使得 Service 只能从集群内访问。
2)NodePort - 使用 NAT 在集群中每个选定 Node 的相同端口上公开 Service 。使用< NodeIP >:< NodePort > 从集群外部访问 Service。是 ClusterIP 的超集。
3)LoadBalancer - 在当前云中创建一个外部负载均衡器(如果支持的话),并为 Service 分配一个固定的外部IP。是 NodePort 的超集。
4)ExternalName - 通过返回带有该名称的 CNAME 记录,使用任意名称(由 spec 中的externalName指定)公开 Service。不使用代理。这种类型需要kube-dns的v1.7或更高版本。
kubectl get services
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT
curl $(minikube ip):$NODE_PORT
kubectl get pods -l app=kubernetes-bootcamp
kubectl get services -l app=kubernetes-bootcamp
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
kubectl label pods $POD_NAME version=v1
kubectl describe pods $POD_NAME
kubectl get pods -l version=v1
kubectl delete service -l app=kubernetes-bootcamp
kubectl get services
curl $(minikube ip):$NODE_PORT
kubectl exec -ti $POD_NAME -- curl localhost:8080
kubectl exec -ti $POD_NAME bash
目标:用 kubectl 扩缩应用程序
https://kubernetes.io/zh/docs/tutorials/kubernetes-basics/scale/scale-intro/
在之前的模块中,我们创建了一个 Deployment,然后通过 Service让其可以开放访问。Deployment 仅为跑这个应用程序创建了一个 Pod。 当流量增加时,我们需要扩容应用程序满足用户需求。扩缩是通过改变 Deployment 中的副本数量来实现的。
kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2
kubectl describe pod nginx-deployment
https://blog.csdn.net/m0_46629123/article/details/124001320
https://blog.csdn.net/m0_46629123/article/details/124002294
yml档案可参考https://cloud.tencent.com/developer/article/1847421
https://blog.csdn.net/weixin_40274679/article/details/107887678
Pods that run a single container. The “one-container-per-Pod” model is the most common Kubernetes use case; in this case, you can think of a Pod as a wrapper around a single container, and Kubernetes manages the Pods rather than the containers directly.
apiVersion: v1
kind: Pod
metadata:
name: mywebsite-pod
labels:
app: Lab1
spec:
containers:
- name: web
image: nginx:latest
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
name: mywebsite-port
protocol: TCP
[lighthouse@VM-8-10-centos ~]$ kubectl describe pod mywebsite-pod2
Name: mywebsite-pod2
Namespace: default
Priority: 0
Node: vm-8-10-centos/10.0.8.10
Start Time: Mon, 11 Apr 2022 20:51:23 +0800
Labels: app=Lab1
Annotations: <none>
Status: Running
IP: 10.42.0.11
IPs:
IP: 10.42.0.11
Containers:
web:
Container ID: containerd://fabf4726d078a431af2e9c4bbdc188033e7f424686b2b222b42688899132d820
Image: nginx:latest
Image ID: docker.io/library/nginx@sha256:2275af0f20d71b293916f1958f8497f987b8d8fd8113df54635f2a5915002bf1
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 11 Apr 2022 20:51:40 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 250m
memory: 256Mi
Requests:
cpu: 100m
memory: 128Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-fw4gh (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-fw4gh:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-fw4gh
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m16s default-scheduler Successfully assigned default/mywebsite-pod2 to vm-8-10-centos
Normal Pulling 4m16s kubelet Pulling image "nginx:latest"
Normal Pulled 4m kubelet Successfully pulled image "nginx:latest" in 15.947986655s
Normal Created 4m kubelet Created container web
Normal Started 4m kubelet Started container web
[lighthouse@VM-8-10-centos ~]$ curl 10.42.0.11
<!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>
apiVersion: v1
kind: Service
metadata:
name: mywebsite-svc
labels:
app: Lab1
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
selector:
app: Lab1
[lighthouse@VM-8-10-centos ~]$ kubectl describe svc mywebsite-svc
Name: mywebsite-svc
Namespace: default
Labels: app=Lab1
Annotations: <none>
Selector: app=Lab1
Type: NodePort
IP Families: <none>
IP: 10.43.124.199
IPs: 10.43.124.199
Port: <unset> 8080/TCP
TargetPort: 80/TCP
NodePort: <unset> 30640/TCP
Endpoints: 10.42.0.11:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
内网IP< NodeIP > 10.0.8.10
NodePort< NodePort > 30640
Pods that run multiple containers that need to work together. A Pod might encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers might form a single cohesive unit of service–one container serving files from a shared volume to the public, while a separate “sidecar” container refreshes or updates those files. The Pod wraps these containers and storage resources together as a single manageable entity. The Kubernetes Blog has some additional information on Pod use cases.
kubectl create -f db-pod.yml -f db-svc.yml -f web-pod.yml -f web-svc.yml
apiVersion: v1
kind: Pod
metadata:
name: db-pod
labels:
app: Lab2-db
spec:
containers:
- name: mysql
image: mysql:5.7
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
ports:
- containerPort: 3306
name: mysql-port
protocol: TCP
env:
-
name: "MYSQL_ROOT_PASSWORD"
value: "password"
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
# type: LoadBalancer
ports:
- port: 3306
name: mysql-port
targetPort: 3306
protocol: TCP
selector:
app: Lab2-db
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
type: NodePort
ports:
- port: 80
name: http
targetPort: 5000
protocol: TCP
selector:
app: Lab2-web
PS: LoadBalancer: 在使用一个集群内部IP地址和在NodePort上开放一个服务之外,向云提供商申请一个负载均衡器,会让流量转发到这个在每个节点上以< NodeIP >:NodePort的形式开放的服务上。LoadBalancer可以隐藏IP地址。
链接
apiVersion: v1
kind: Pod
metadata:
name: web-pod
labels:
app: Lab2-web
spec:
containers:
- name: redis
image: redis
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 6379
name: redis-port
protocol: TCP
- name: python
image: seasonzhang/py-red-sql
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
env:
- name: "REDIS_HOST"
value: "localhost"
ports:
- containerPort: 5000
name: python-port
protocol: TCP
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web-ingress
spec:
rules:
- host: web-ingress.8801112.10.34.4.101.xip.io
http:
paths:
- backend:
serviceName: web-svc
servicePort: 5000
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
type: LoadBalancer
ports:
- port: 3306
name: mysql-port
targetPort: 3306
protocol: TCP
selector:
app: Lab2-db
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-dp
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello
image: nginx
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: hello-svc
spec:
type: NodePort
ports:
- port: 80
name: http
targetPort: 3000
protocol: TCP
selector:
app: hello-world
kubectl scale deployment hello-dp --replicas 5
#更新image版本
kubectl set image deployment hello-dp hello=nginx
#查看更新状态
kubectl rollout status deploy/hello-dp
#暂停更新
kubectl rollout pause deploy/hello-dp
#回复
kubectl rollout resume deploy/hello-dp
#查看更新历史
kubectl rollout history deploy/hello-dp
#撤销
kubectl rollout undo deploy/hello-dp
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: hello-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hello-dp
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 50
介绍PVC
有两种方式配置PV:静态的或动态的。以下示范的是动态的。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
#storageClassName: longhorn
resources:
requests:
storage: 1Gi
apiVersion: v1
kind: Service
metadata:
name: my-svc
labels:
app: Lab5
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
selector:
app: Lab5
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: Lab5
spec:
containers:
- name: myfrontend
image: nginx
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
volumeMounts:
- name: mypd
mountPath: "/usr/share/nginx/html"
volumes:
- name: mypd
persistentVolumeClaim:
claimName: my-pvc
整体效果:pod删除后,PVC保存原来的信息,新的pod启动后,还可以读取到。
看11.configMap介绍即可
看12.secret介绍即可
效果:用内网IP加端口curl 10.0.8.10:32247就可以访问应用。目前用公网IP无法访问,正在debug。
apiVersion: v1
kind: Service
metadata:
name: chengjisihan-svc
labels:
app: chengji-Lab1
spec:
type: NodePort
ports:
- port: 8000
targetPort: 8000
protocol: TCP
selector:
app: chengji-Lab1
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod
labels:
app: chengji-Lab1
spec:
containers:
- name: web
image: seasonzhang/chengjisihanv3:1.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod
protocol: TCP
https://blog.csdn.net/m0_46629123/article/details/124144199
跟13A差不多,只是NodePort换成了LoadBalancer。
以下4种方式都可以访问应用:
1.浏览器输入106.52.14.84:8000
2.curl 106.52.14.84:8000
3.curl 10.0.8.10:8000
4.curl 10.0.8.10:32247
apiVersion: v1
kind: Service
metadata:
name: chengjisihan-svc
labels:
app: chengji-Lab1
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8000
targetPort: 8000
protocol: TCP
selector:
app: chengji-Lab1
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod
labels:
app: chengji-Lab1
spec:
containers:
- name: web
image: seasonzhang/chengjisihanv3:1.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod
protocol: TCP
https://blog.csdn.net/watermelonbig/article/details/84108424
emptyDir Volume对于容器来说是持久的,对于Pod则不是。当Pod从节点删除时,Volume的内容也会被删除。但如果只是容器被销毁而Pod还在,则Volume不受影响。也就是说:emptyDir Volume的生命周期与Pod一致。
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- image: busybox
name: test-emptydir
command: [ "sleep", "3600" ]
volumeMounts:
- mountPath: /data
name: data-volume
volumes:
- name: data-volume
emptyDir: {}
# kubectl describe pod test-pod
Name: test-pod
Namespace: default
Node: kube-node2/172.16.10.102
......
Environment: >
Mounts:
/data from data-volume (rw)
......
Volumes:
data-volume:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
......
hostPath允许挂载Node上的文件系统到Pod里面去。如果Pod有需要使用Node上的文件,可以使用hostPath。
apiVersion: v1
kind: Pod
metadata:
name: test-pod2
spec:
containers:
- image: busybox
name: test-hostpath
command: [ "sleep", "3600" ]
volumeMounts:
- mountPath: /test-data
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
# kubectl describe pod test-pod2
Name: test-pod2
Namespace: default
Node: kube-node2/172.16.10.102
......
Mounts:
/test-data from test-volume (rw)
......
Volumes:
test-volume:
Type: HostPath (bare host directory volume)
Path: /data
HostPathType: Directory
......
echo 'testtesttest' > /test-data/test.log
我们把该pod删除掉,再看看node节点上的hostPath使用的目录与数据会有什么变化。
kubectl delete pod test-pod2
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod4
labels:
app: chengji-pod4
spec:
containers:
- name: chengji4
image: seasonzhang/chengjisihanv3:2.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod4
protocol: TCP
volumeMounts:
- name: mypd4
mountPath: /code/package/file
volumes:
- name: mypd4
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: chengji-svc4
labels:
app: chengji-pod4
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8334
#name: http
targetPort: 8000
protocol: TCP
selector:
app: chengji-pod4
---
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod5
labels:
app: chengji-pod5
spec:
containers:
- name: chengji5
image: seasonzhang/chengjisihanv3:2.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod5
protocol: TCP
volumeMounts:
- name: mypd5
mountPath: /code/package/SQL
volumes:
- name: mypd5
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: chengji-svc5
labels:
app: chengji-pod5
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8335
#name: http
targetPort: 8000
protocol: TCP
selector:
app: chengji-pod5
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: chengji-dp6
spec:
replicas: 3
selector:
matchLabels:
app: chengji-pod6
template:
metadata:
labels:
app: chengji-pod6
spec:
containers:
- name: chengji6
image: seasonzhang/chengjisihanv3:2.0
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod6
protocol: TCP
volumeMounts:
- name: mypd6
mountPath: /code/package/file
volumes:
- name: mypd6
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: chengji-svc6
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8336
#name: http
targetPort: 8000
protocol: TCP
selector:
app: chengji-pod6
要在Pod中使用ESB volume,必须先在AWS中创建,然后通过volume-id引用。
PersistentVolume(PV)是外部存储系统中的一块存储空间,由管理员创建和维护。与Volume一样,PV具有持久性,生命周期独立于Pod。
PersistentVolumeClaim(PVC)是对PV的申请(Claim)。PVC通常由普通用户创建和维护。需要为Pod分配存储资源时,用户可以创建一个PVC,指明存储资源的容量大小和访问模式(比如只读)等信息,Kubernetes会查找并提供满足条件的PV。
类似于7E.lab 5
我可以起PVC,但是SQLite好像保存不成功,所有的记录都被清空了。
tips:我好像PVC没有绑成功,因为还是pending状态。看看如何debug。
apiVersion: apps/v1
kind: Deployment
metadata:
name: chengji-dp3
spec:
replicas: 1
selector:
matchLabels:
app: chengji-pod3
template:
metadata:
labels:
app: chengji-pod3
spec:
containers:
- name: chengji3
image: seasonzhang/chengjisihanv3:2.0
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod3
protocol: TCP
volumeMounts:
- name: mypd3
mountPath: "/code/package/SQL"
volumes:
- name: mypd3
persistentVolumeClaim:
claimName: my-pvc3
---
apiVersion: v1
kind: Service
metadata:
name: chengji-svc3
labels:
app: chengji-pod3
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8331
#name: http
targetPort: 8000
protocol: TCP
selector:
app: chengji-pod3
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc3
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
#storageClassName: longhorn
resources:
requests:
storage: 1Gi
类似于7E.lab 5
PVC绑pod路径下的文件是ok的。
效果:重启pod时,1.txt可以保留。
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod3
labels:
app: chengji-pod3
spec:
containers:
- name: chengji3
image: seasonzhang/chengjisihanv3:2.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod3
protocol: TCP
volumeMounts:
- name: mypd3
mountPath: "/code/package/SQL/"
volumes:
- name: mypd3
persistentVolumeClaim:
claimName: my-pvc3
---
apiVersion: v1
kind: Service
metadata:
name: chengji-svc3
labels:
app: chengji-pod3
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8331
#name: http
targetPort: 8000
protocol: TCP
selector:
app: chengji-pod3
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc3
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
#storageClassName: longhorn
resources:
requests:
storage: 1Gi
echo ‘Hello from Kubernetes storage’ > /code/package/SQL/1.txt
把pod删掉,然后用yaml档案再起一个,你会发现1.txt仍然存在。
Season Zhang:alex老师,我发现我的pod的PVC如果包含SQLite,django就无法读取SQLite了。PVC倒是可以保存我新增的文件,如TXT。
Alex Lu:無法連到Database的原因是因為將Web AP拆成兩個Container之後, web 的connection string仍然用server=(local), 應該要改成Database所在的container name, 課件裡面應該有提到, 所以你的問題與PVC無關
参考https://blog.csdn.net/m0_46629123/article/details/124810972
步骤1:应用启动时,会将数据从持久卷同步到应用中。因为hostpath: /data为空,故第一次部署时,数据库是空的。
步骤2:应用启动后,数据会从应用同步到持久卷。故在部署后的应用网站上传数据后,数据会同步到hostpath: /data。
步骤3:应用关闭后,数据会保存在持久卷中。
步骤4:将重启pod或deployment后,持久卷会重复步骤1-----应用启动时,会将数据从持久卷同步到应用中。
Docker:如何将sqlite数据库更改持久保存到db文件?https://qa.1r1g.com/sf/ask/3230348761/?lastactivity
https://blog.csdn.net/m0_46629123/article/details/124810972
步骤1:建立PVC。
步骤2:第一次启动应用时,先拷贝cp SQLite到/data,用/data挂PVC来初始化PVC的值。不要将应用的SQLite直接挂PVC。
步骤3:PVC有初始值后,再将SQLite的文件夹来跟PVC对应。所以第二次回去应用,将原来/data挂PVC取消掉,改为SQLite挂PVC。
步骤4:应用关闭和重启后,数据会保存在持久卷中。
截图待更新
https://blog.csdn.net/m0_46629123/article/details/124144654
https://hub.docker.com/_/nginx?tab=tags
image: nginx
image: nginx:stable-alpine-perl
image: seasonzhang/chengjisihanv3:1.0
kubectl create configmap myconfigmap --from-literal=name=season --from-literal=password=123456
name=season
password=123456
kind: ConfigMap
apiVersion: v1
metadata:
name: myconfigmap2
namespace: default
data:
name: season
password: '123456'
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod-4
spec:
containers:
- name: test-container-nginx
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: myconfigmap
itmes:
- key:name
path:myApp/name
restartPolicy: Never
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: nginx
env:
- name: CONFIGMAP_NAME
valueFrom:
configMapKeyRef:
name: myconfigmap2
key: name
- name: CONFIGMAP_PASSWORD
valueFrom:
configMapKeyRef:
name: myconfigmap2
key: password
restartPolicy: Never
kubectl create configmap myconfigmap --from-literal=name=season --from-literal=password=123456
name=season
password=123456
kind: Secret
apiVersion: v1
metadata:
name: mysecret2
namespace: default
data:
name: c2Vhc29u
password: MTIzNDU2
#name: season
#password: '123456'
apiVersion: v1
kind: Pod
metadata:
name: secretpod
spec:
containers:
- name: test-container-nginx
image: nginx
volumeMounts:
- name: secrets
mountPath: /app/secrets
readOnly: true
volumes:
- name: secrets
secret:
secretName: mysecret2
apiVersion: v1
kind: Pod
metadata:
name: secret-test
spec:
containers:
- name: secret-test
image: nginx
env:
- name: SECRET_NAME
valueFrom:
secretKeyRef:
name: mysecret2
key: name
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: mysecret2
key: password
restartPolicy: Never