阿汤博客-承接中小企业服务器维护和网站维护,有意者可以联系博主!

Kubernetes部署Nginx+PV(nfs)+service

运维文档 192℃ 0评论

1、安装nfs设置共享(生产环境建议使用云服务商提供的云共享存储如:阿里云的NAS,AWS的EBS)

#yum install nfs-utils  #每个节点安装

#systemctl enable nfs

#mkdir -p /var/data/ui2

#cat /etc/exports

/var/data 192.168.15.0/24(rw,async)


2、创建namespace

#cat namespaces.yml

apiVersion: v1
kind: Namespace
metadata:
   name: nginx-ingress
   labels:
     name: nginx-ingress

3、创建pv

#cat ui2-pv.yml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: ui2-pv
  namespace: nginx-ingress
  labels:
    pv: ui2-pv
spec:
  capacity:
    storage: 800Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs
  nfs:
    path: /var/data/ui2
    server: 192.168.15.100

4、创建pvc

#cat ui2-pvc.yml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ui2-pvc
  namespace: nginx-ingress
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 800Mi
  storageClassName: nfs
  selector:
    matchLabels:
      pv: ui2-pv

5、创建Nginx

#cat nginx-ui2.yml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx
  namespace: nginx-ingress
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: web_server
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.2
        ports:
        - containerPort: 80
#- containerPort: 443
          name: nginx
        volumeMounts:
        - name: nginx-persistent-storage
          mountPath: /usr/share/nginx/html
      volumes:
        - name: nginx-persistent-storage
          persistentVolumeClaim:
            claimName: ui2-pvc

6、创建service

#cat service-ui2.yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
#  type: NodePort #可以使用nodeport或者默认clusterip方式
  selector:
    app: web_server
  ports:
  - protocol: TCP       
    port: 80
    targetPort: 80
  - protocol: TCP
    name: https
    port: 443
    targetPort: 443

Kubernetes部署Nginx+PV(nfs)+service

转载请注明:阿汤博客 » Kubernetes部署Nginx+PV(nfs)+service

喜欢 (0)or分享 (0)