yaml介绍:

https://www.jianshu.com/p/1d41ef5bba53

k3s kubectl apply -f svc.yaml  

k3s kubectl get svc
k3s kubectl get svc -o wide --namespace=nginx
k3s kubectl get svc -n nginx
k3s kubectl delete svc ngx-svc -n nginx  或者 --namespace=nginx


测试:宿主机的ip
http://192.168.0.52:8080/









yaml

apiVersion: v1
kind: Service
metadata: 
  name: ngx-svc
  #namespace: nginx
spec: 
  type: NodePort #配置为NodePort,外部可以访问
  selector:
    app: nginx2   #选择器
  ports:
    - name: http
      port: 80       #容器间,服务调用的端口
      targetPort: 80    #容器暴露的端口,与Dockerfile暴露端口保持一致
      nodePort: 8080   #NodePort,外部访问的端口
      #protocol: TCP    #协议
    - name: http2
      port: 8080
      targetPort: 8080
      nodePort: 8088