k3d | nodeport方式访问nginx的service

系统与环境

vmware ubuntu18
linux
docker 我写的教程
k3d+kubectl 我写的教程

步骤

根据网上的教程:https://github.com/rancher/k3d/blob/main/docs/usage/guides/exposing_services.md

  1. 创建1个server+2个agents的集群
k3d cluster create mycluster -p "8082:30080@agent[0]" --agents 2
  1. 创建nginx的pod
 kubectl create deployment nginx --image=nginx:latest
  1. 根据[网上的教程](kubectl apply -f nginx-service.yaml service),service.yaml如下:
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  ports:
  - name: 80-80
    nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort
kubectl apply -f nginx-service.yaml service
  1. 访问 localhost:8082
    localhost指虚拟机的ip


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容