欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

k8s离线部署学习-服务部署(nginx)

程序员文章站 2022-05-27 19:17:37
...

准备Nginx镜像,并推送到仓库

docker load -i nginx.tar

docker tag nginx:1.18 10.0.7.125:8000/library/nginx:1.18

docker push 10.0.7.125:8000/library/nginx:1.18

nginx-pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 1Gi

nginx-deploy

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: 10.0.7.125:8000/library/nginx:1.18
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: /usr/share/nginx/html
              name: nginx
      volumes:
        - name: nginx
          persistentVolumeClaim:
            claimName: nginx

nginx-svc

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30000

访问

http://10.0.7.70:30000