二进制k8s集群安装ingress-controller

环境准备

##/etc/hosts
192.168.48.101 master01
192.168.48.102 master02
192.168.48.103 master03
192.168.48.201 node01
192.168.48.202 node02
## keepalived的vip
192.168.48.66
IPHostnameCPUMemory
192.168.48.101master0124G
192.168.48.102master0224G
192.168.48.103master0324G
192.168.48.201node0124G
192.168.48.202node0224G
软件版本
kubernetes1.15.2
docker-ce19.03
calico3.8
etcd3.3.13
CNI0.8.1
coredns1.4.0
metrics-server0.3.3
ingress-controller0.25.0

安装

官方地址

https://github.com/kubernetes/ingress-nginx

yaml文件下载

wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.25.0/deploy/static/mandatory.yaml

镜像下载

需要的镜像

quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.25.0

链接: https://pan.baidu.com/s/1_n_IPRo2bojl2EIoaqqcUg 提取码: tjyt

节点导入镜像

docker load -i ingress-controller-nginx-0.25.0.tar.gz 

以hostnetwork暴露出去

给master01打标签
[root@master01 ~]# kubectl label node master01 app=ingress
node/master01 labeled
编辑yaml文件
[root@master01 ~]# vim mandatory.yaml 
...
      spec:
      serviceAccountName: nginx-ingress-serviceaccount
      hostNetwork: true
      nodeSelector:
        app: ingress
      tolerations:
        - key: "node-role.kubernetes.io/master"
          operator: "Exists"
          effect: "NoSchedule"

在这里插入图片描述

创建ingress-controller

[root@master01 ~]# kubectl apply -f mandatory.yaml 
namespace/ingress-nginx created
configmap/nginx-configuration created
configmap/tcp-services created
configmap/udp-services created
serviceaccount/nginx-ingress-serviceaccount created
clusterrole.rbac.authorization.k8s.io/nginx-ingress-clusterrole created
role.rbac.authorization.k8s.io/nginx-ingress-role created
rolebinding.rbac.authorization.k8s.io/nginx-ingress-role-nisa-binding created
clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress-clusterrole-nisa-binding created
deployment.apps/nginx-ingress-controller created
如果出现报错,看看日志

修改mandatory.yaml

在ClusterRole中添加权限

  - apiGroups:
      - "extensions"
      - "networking.k8s.io"
   
  - apiGroups:
      - "extensions"
      - "networking.k8s.io"

kubectl delete -f mandatory.yaml

kubectl apply -f mandatory.yaml
[root@master01 ~]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      58685/nginx: master 
tcp        0      0 0.0.0.0:8181            0.0.0.0:*               LISTEN      58685/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      58685/nginx: master 
tcp6       0      0 :::10254                :::*                    LISTEN      58658/nginx-ingress 

[root@master01 ~]# kubectl get pods --all-namespaces  -o wide
NAMESPACE       NAME                                        READY   STATUS    RESTARTS   AGE    IP               NODE       NOMINATED NODE   READINESS GATES
ingress-nginx   nginx-ingress-controller-56846d8679-ptsn5   1/1     Running   0          2m9s   192.168.48.101   master01   <none>           <none>
kube-system     calico-kube-controllers-7bd78b474d-r2tdd    1/1     Running   2          32h    10.244.235.3     master03   <none>           <none>
kube-system     calico-node-cfckb                           1/1     Running   2          32h    192.168.48.103   master03   <none>           <none>
kube-system     calico-node-kzqg6                           1/1     Running   2          32h    192.168.48.102   master02   <none>           <none>
kube-system     calico-node-msmv2                           1/1     Running   2          32h    192.168.48.202   node02     <none>           <none>
kube-system     calico-node-p2kvc                           1/1     Running   2          32h    192.168.48.201   node01     <none>           <none>
kube-system     calico-node-q8tr4                           1/1     Running   2          32h    192.168.48.101   master01   <none>           <none>
kube-system     coredns-5c6c9cf6c8-9jn9z                    1/1     Running   0          48s    10.244.196.133   node01     <none>           <none>
kube-system     coredns-5c6c9cf6c8-qg7kv                    1/1     Running   0          82s    10.244.140.68    node02     <none>           <none>
kube-system     metrics-server-55cb6d6b57-m9clg             1/1     Running   1          11h    10.244.196.132   node01     <none>           <none>

测试

vim nginx-ingress.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  rules:
  - host: nginx.tk8s.com
    http:
      paths:
      - backend:
          serviceName: nginx
          servicePort: 80

[root@master01 ~]# kubectl apply -f nginx-ingress.yaml 
deployment.extensions/nginx created
service/nginx created
ingress.extensions/nginx-ingress created

[root@master01 ~]# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bffc778db-97vxv   1/1     Running   0          7m2s
[root@master01 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   35h
nginx        ClusterIP   10.109.43.247   <none>        80/TCP    7m7s
[root@master01 ~]# kubectl get ingresses
NAME            HOSTS            ADDRESS   PORTS   AGE
nginx-ingress   nginx.tk8s.com             80      7m12s

在这里插入图片描述
在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐