k3s搭建nginx验证

root@qwq:/home/qwq# cat nginx.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 6
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30001
  type: NodePort

Deployment部分:定义了一个名为nginx-deployment的Deployment,用于部署nginx应用程序。其中指定了副本数量为6个,selector使用app: nginx来选择要管理的Pod,template中定义了一个名为nginx的容器,使用nginx镜像,监听80端口。

Service部分:定义了一个名为nginx-service的Service,用于暴露nginx应用程序的服务。selector使用app: nginx来选择要路由流量的Pod,端口设置为80,目标端口也为80,NodePort设置为30001,类型为NodePort,表示这个Service会在每个节点上绑定30001端口,以便外部可以通过访问节点的IP地址和这个端口来访问nginx服务。

posted @ 2024-03-12 08:38  iXiAo9  阅读(53)  评论(0编辑  收藏  举报