Kubernetes部署Nginx+PV(nfs)+service

2019年6月5日10:42:05 发表评论 2,148 ℃

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

精选全网爆款产品,爆品销量榜单,全场低至0元起,还有更多云产品免费试用,带你0门槛上云

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: