k8s使用Deployment创造三副本pod nginx 并映射文件夹后添加hellow.html 详细做法
时间: 2023-04-02 10:04:34 浏览: 216
您好,以下是使用Deployment创建三个副本的nginx pod并映射文件夹并添加helloworld.html的详细步骤:
1. 创建一个名为nginx-deployment.yaml的文件,其中包含以下内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
configMap:
name: nginx-config
items:
- key: helloworld.html
path: helloworld.html
2. 创建一个名为nginx-config.yaml的文件,其中包含以下内容:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
helloworld.html: |
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
3. 运行以下命令以创建ConfigMap:
kubectl apply -f nginx-config.yaml
4. 运行以下命令以创建Deployment:
kubectl apply -f nginx-deployment.yaml
5. 运行以下命令以检查Deployment是否成功创建:
kubectl get deployments
6. 运行以下命令以检查Pod是否成功创建:
kubectl get pods
7. 运行以下命令以检查Pod的详细信息:
kubectl describe pods
8. 运行以下命令以访问helloworld.html:
kubectl port-forward <nginx-pod-name> 808:80
然后在浏览器中访问http://localhost:808/helloworld.html,您应该能够看到“Hello, World!”的消息。
希望这可以帮助您!
阅读全文
相关推荐














