k8s部署vue项目

1、准备工作

kubectl version
Client Version: v1.28.2

首先制作vue项目的docker image,然后上传至仓库
没有docker镜像仓库的可以参考教程 https://blog.csdn.net/qq_41076892/article/details/139692963

2、运行yaml

# accumulation-ui.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: accumulation-ui
  namespace: dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app: accumulation-ui
  template:
    metadata:
      labels:
        app: accumulation-ui
    spec:
      containers:
        - name: accumulation-ui
          image: 192.168.255.132/library/accumulation-ui:202406130100
          imagePullPolicy: IfNotPresent
          ports:
            - name: rest
              containerPort: 80
              protocol: TCP
kubectl apply -f accumulation-ui.yaml

# 查看是否成功运行
[root@k8s-master vue]# kubectl get pod -n dev |grep accumulation-ui
accumulation-ui-58557f496-hbv6d                                   1/1     Running   0                49m

3、创建service和ingress

# accumulation-svc-ingress.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: accumulation-ui-svc
  namespace: dev
spec:
  selector:
    app: accumulation-ui
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  clusterIP: None
  type: ClusterIP

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: accumulation-ingress
  namespace: dev
spec:
  ingressClassName: nginx
  rules:
    - host: nginx.demo.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: accumulation-ui-svc
                port:
                  number: 80
kubectl apply -f accumulation-svc-ingress.yaml

[root@k8s-master vue]# kubectl get svc,ingress -n dev | grep accumulation
service/accumulation-ui-svc   ClusterIP   None            <none>        80/TCP         93m
ingress.networking.k8s.io/accumulation-ingress   nginx   nginx.demo.com,tomcat.demo.com             192.168.255.143   80      93m

验证:在Windows,hosts文件添加
192.168.255.143 nginx.demo.com
浏览器输入域名,nginx.demo.com,正常加载,说明成功。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值