文章目录
操作步骤:
K8S环境
在 master 下操作
cd /opt/demo 路径下
新建nginx 首页文件,测试用
vim index.html
<h1> this is hello,waorld!</h1>
写入首页文件
创建configmap 资源
kubectl create configmap index-config --from-file=index.html
//configmap 资源 的删除方式
kubectl delete configmap index-config
创建nginx 的 deployment资源
vim nginx-demount.yaml
apiVersion: apps/v1
kind: Deployment //资源类型
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2 //副本数
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx2
image: nginx:1.15.4
ports:
- containerPort: 80
volumeMounts:
- name: nginx-volume //自定义的名字和下面保持一致
mountPath: /usr/share/nginx/html // nginx 的首页站点目录,挂载点
volumes:
- name: nginx-volume //自定义的名字和上面保持一致
configMap:
name: index-config cmap资源名称,需要挂载的资源
restartPolicy: Always //重启策略
创建资源
kubectl create -f nginx-demount.yaml
-------------------------------------------
创建 service 发布nginx服务
[root@master demo]# kubectl expose nginx-deployment --port=80 --target-port=80 --type=NodePort --name nginx-server1
查看确认
[root@master demo]# kubectl get pods,svc -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/mynginx 1/1 Running 0 157m 10.244.2.18 node1 <none> <none>
pod/mypod 0/1 Completed 0 18h 10.244.2.13 node1 <none> <none>
pod/nginx-deployment-565867559d-t9nfh 1/1 Running 0 2m27s 10.244.1.19 node2 <none> <none>
pod/nginx-deployment-565867559d-vr54z 1/1 Running 0 2m27s 10.244.2.26 node1 <none> <none>
pod/tomcat-7989d99887-q98c9 1/1 Running 2 22h 10.244.1.12 node2 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4m45s <none>
service/nginx-server1 NodePort 10.96.228.123 <none> 80:31321/TCP 23s app=ngi
访问节点IP:31321 测试
修改首页站点文件测试
此处为了测试方便,直接修改了yaml 文件资源
[root@master demo]# kubectl get cm //查看ConfigMAP资源
NAME DATA AGE
index-config 1 78m
myconfig 2 19h
redis-config 1 19h
[root@master demo]# kubectl describe cm index-config
Name: index-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
index.html:
----
<h1> this is hello,waorld!</h1>
Events: <none>
修改 cm 资源 ,达到修改网页的目的
[root@master demo]# kubectl edit configmap index-config
configmap/index-config edited