httpd部署

创建共享存储目录

yum install -y rpcbind nfs-utils
创建共享目录
mkdir -p /home/sharedir/www
修改目录权限
chmod 0755 -R sharedir
修改NFS配置文件
vi /etc/exports
/home/sharedir 192.168.2.0(rw,no_root_squash,no_all_squash,sync)
启动nfs:systemctl start nfs

pv创建文档
vi httpd-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: httpd-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  nfs:
    path: /home/sharedir/www
    server: 192.168.2.120

pvc创建文档
vi httpd-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: httpd-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

httpd创建文件
vi httpd.yaml

apiVersion: v1
kind: Service
metadata:
  name: httpd
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 32222
    targetPort: 80
  selector:
    app: httpd
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd
spec:
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - name: httpd
        image: httpd
        ports:
        - name: httpd
          containerPort: 80
        volumeMounts:
        - name: httpd-persistent-storage
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: httpd-persistent-storage
        persistentVolumeClaim:
          claimName: httpd-pvc

执行资源创建
kubectl apply -f httpd-pv.yaml
kubectl apply -f httpd-pvc.yaml
kubectl apply -f httpd.yaml

查看容器
[root@master mysql]# kubectl get pod
NAME READY STATUS RESTARTS AGE
httpd-65c5d64bd7-pmwwr 1/1 Running 0 2m19s

查看服务
[root@master mysql]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
httpd NodePort 10.103.239.58 <none> 80:32222/TCP 22m

进入httpd容器
[root@master mysql]# kubectl exec -it httpd-65c5d64bd7-pmwwr bash
root@httpd-65c5d64bd7-pmwwr:/usr/local/apache2#

访问站点:
http://192.168.2.122:32222/

修改副本数量

kubectl scale deployment httpd --replicas=2

 

posted @ 2019-09-05 17:36  BicycleBoy  阅读(444)  评论(0编辑  收藏  举报