1. 安装部署ingress-nginx
前言:坑比较多,pod启动running成功也并不代表ingress就能使用,需要进去pod内查看logs还有pod的描述也要看看是否有报错。
文件地址:
# 1.替换镜像
sed -i s#k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660#registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1#g deploy.yaml
sed -i s#k8s.gcr.io/ingress-nginx/controller:v1.1.1@sha256:0bc88eb15f9e7f84e8e56c14fa5735aaa488b840983f87bd79b1054190e660de#registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.1.1#g deploy.yaml
# 2.部署
kubectl apply -f deploy.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
configmap/ingress-nginx-controller created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
service/ingress-nginx-controller-admission created
service/ingress-nginx-controller created
deployment.apps/ingress-nginx-controller created
ingressclass.networking.k8s.io/nginx created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
serviceaccount/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
# 3.查看pod
kubectl get pod -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-6njdx 0/1 Completed 0 14m
ingress-nginx-admission-patch-ngp42 0/1 Completed 0 14m
ingress-nginx-controller-85bf97579b-zgvdh 1/1 Running 0 9m7s
# 4.查看pod运行情况
kubectl describe pod -n ingress-nginx ingress-nginx-controller-74c6bcdc65-dttbv
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 115s default-scheduler Successfully assigned ingress-nginx/ingress-nginx-controller-74c6bcdc65-dttbv to k8s-node02
Warning FailedMount 114s (x2 over 115s) kubelet MountVolume.SetUp failed for volume "webhook-cert" : secret "ingress-nginx-admission" not found
Normal Pulled 112s kubelet Container image "registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.1.1" already present on machine
Normal Created 112s kubelet Created container controller
Normal Started 112s kubelet Started container controller
Normal RELOAD 110s nginx-ingress-controller NGINX reload triggered due to a change in configuration
日志报错信息:MountVolume.SetUp failed for volume "webhook-cert" : secret "ingress-nginx-admission" not found。
参考文档:https://juejin.cn/post/7099413476967514125#heading-5
查看secret:
kubectl get secret -A|grep ingress
ingress-nginx default-token-bk2hf kubernetes.io/service-account-token 3 10m
ingress-nginx ingress-nginx-admission Opaque 3 10m
ingress-nginx ingress-nginx-admission-token-fg9jn kubernetes.io/service-account-token 3 10m
ingress-nginx ingress-nginx-token-qd9n9 kubernetes.io/service-account-token 3 10m
修改如下:
vim deploy.yaml
404 terminationGracePeriodSeconds: 300
405 volumes:
406 - name: webhook-cert
407 secret:
408 secretName: ingress-nginx-admission-token-fg9jn # 修改成我们上面找到的secret
重新部署:
kubectl apply -f deploy.yaml
# 查看日志看有没有之前的报错
kubectl describe pod -n ingress-nginx ingress-nginx-controller-85bf97579b-zgvdh
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 15m default-scheduler Successfully assigned ingress-nginx/ingress-nginx-controller-85bf97579b-zgvdh to k8s-node02
Normal Pulled 15m kubelet Container image "registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.1.1" already present on machine
Normal Created 15m kubelet Created container controller
Normal Started 15m kubelet Started container controller
Normal RELOAD 15m nginx-ingress-controller NGINX reload triggered due to a change in configuration
编辑Ingress的svc,改为NodePort:
kubectl edit svc ingress-nginx-controller -n ingress-nginx
#将type:LoadBalancer --------> 改为type:NodePorts
访问Ingress:
kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.100.92.223 <none> 80:30081/TCP,443:30728/TCP 16m
ingress-nginx-controller-admission ClusterIP 10.102.32.53 <none> 443/TCP 16m
标签:ingress,created,admission,nginx,controller,1.23,k8s
From: https://www.cnblogs.com/-k8s/p/17339990.html