部署deployment和service
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
namespace: dalong
spec:
replicas: 2
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
spec:
containers:
- image: nginx:1.18
imagePullPolicy: Always
name: web
resources: {}
---
apiVersion: v1
kind: Service
metadata:
name: web
namespace: dalong
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web
type: NodePort
ingress.yaml如下,画红线部分一定要加
在另一台机器上配置host
//下面这行配置在hosts文件中 192.168.37.131即worker1 的ip
//通过 kubectl get pod -n ingress-nginx -o wide,查看pod所在的主机ip即worker1
192.168.37.131 app.dalong.com
[root@k8s-worker01 tmpdir]# kubectl get pod -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ingress-nginx-admission-create-lkbzx 0/1 Completed 0 12h 10.244.235.145 worker1 <none> <none>
ingress-nginx-admission-patch-5tlgc 0/1 Completed 0 12h 10.244.235.161 worker1 <none> <none>
ingress-nginx-controller-7fcc78fc94-xddz9 1/1 Running 3 12h 10.244.235.187 worker1 <none> <none>
http://app.dalong.com:31970
31970端口号是ingress-nginx命名空间里的nodeport类型的service的端口号;因为安装的ingress的是NodePort类型