检查资源的访问,这里使用nginx-ingress-controller暴露的端口32368访问服务的信息;
#第一种方案可以在对应Node上设置host文件echo '172.21.122.231 aa.bb.cc' >> /etc/hosts
curl aa.bb.cc:32368
#使用curl方式
curl -v :32368 -H 'host: aa.bb.cc'
image.png DaemonSet+HostNetwork+nodeSelector模式
清除资源;
kubectl delete -f v.1.0.0-deploy.yamlkubectl delete -f nginx-nodeport-service.yaml
kubectl delete -f nodeport-ingress.yaml
给Node节点打标签为ingress=nginx;
kubectl label nodes demo-work-1 ingress=nginx编辑v1.0.0-deploy.yaml,找到deployment部分,将kind变为DaemonSet,nodeSelector节点选择器变为ingress等于nginx,增加网络为hostNetwork等于true,这里需要在args新增--watch-ingress-without-class,这样ingress规则才能生效,这个是新版的以后不太一样的地方,链接提取码: dbag;
apiVersion: apps/v1kind: DaemonSet
metadata:
labels:
helm.sh/chart: ingress-nginx-4.0.1
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
selector:
matchLabels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/component: controller
revisionHistoryLimit: 10
minReadySeconds: 0
template:
metadata:
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/component: controller
spec:
dnsPolicy: ClusterFirst
containers:
- name: controller
image: willdockerhub/ingress-nginx-controller:v1.0.0
imagePullPolicy: IfNotPresent
lifecycle:
preStop:
exec:
command:
- /wait-shutdown
args:
- /nginx-ingress-controller
- --election-id=ingress-controller-leader
- --controller-class=k8s.io/ingress-nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=http://www.likecs.com/usr/local/certificates/cert
- --validating-webhook-key=http://www.likecs.com/usr/local/certificates/key
- --watch-ingress-without-class=true # 新增
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
runAsUser: 101
allowPrivilegeEscalation: true
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: LD_PRELOAD
value: /usr/local/lib/libmimalloc.so
livenessProbe:
failureThreshold: 5
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
ports:
- name: http
containerPort: 80
protocol: TCP
- name: https
containerPort: 443
protocol: TCP
- name: webhook
containerPort: 8443
protocol: TCP
volumeMounts:
- name: webhook-cert
mountPath: /usr/local/certificates/
readOnly: true
resources:
requests:
cpu: 100m
memory: 90Mi
nodeSelector:
ingress: nginx
hostNetwork: true
serviceAccountName: ingress-nginx
terminationGracePeriodSeconds: 300
volumes:
- name: webhook-cert
secret:
secretName: ingress-nginx-admission