k8s——部署一个nginx应用

mac2025-04-14  17

创建nginx-deployment.yaml文件

apiVersion: apps/v1 kind: Deployment metadata: name: nginxdeploy spec: replicas: 1 selector: matchLabels: name: nginxdeploy template: metadata: labels: name: nginxdeploy spec: containers: - name: nginxdeploy image: nginx ports: - containerPort: 80

确保所有节点都有nginx镜像

使用kubectl生成pod

kubecet create -f nginx-deployment.yaml

查看

kubectl get pod

创建nginx-service.yaml

apiVersion: v1 kind: Service metadata: name: nginxdeploy spec: type: NodePort ports: - port: 82 protocol: TCP targetPort: 80 name: http nodePort: 30055 selector: name: nginxdeploy

查看创建的service

kubectl get svc

通过cluster-ip与对应的端口号验证

curl 10.96.109.77:82

至此只能通过集群内部访问,外部是访问不了的,需要通过相关配置才能实现

最新回复(0)