kubernetes安装ingress-nginx的步骤
kubernetes安装ingress-nginx的步骤系统版本:CentOs8.1k8s版本:v1.21.3containerd版本:ctr containerd.io 1.4.3一: 准备yaml文件github仓库地址:wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/ma
kubernetes安装ingress-nginx的步骤
系统版本:CentOs8.1
k8s版本:v1.21.3
containerd版本:ctr containerd.io 1.4.3
一: 准备yaml文件
github仓库地址:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
以前用如上的地址下载,现在好像是不灵了
那我们选择ingress-nginx 0.20.0版本 https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0
下载 service-nodeport.yaml
https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/provider/baremetal/service-nodeport.yaml
下载 mandatory.yaml
https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/mandatory.yaml
将镜像地址替换为阿里可下载的地址(略)
#修改service-nodeport.yaml
vim service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 32080 #http这里修改
- name: https
port: 443
targetPort: 443
protocol: TCP
nodePort: 32443 #https这里修改
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
部署
kubectl create namespace ingress-nginx
kubectl apply -f mandatory.yaml
kubectl apply -f service-nodeport.yaml
执行mandatory.yaml有异常报错
error: unable to recognize “mandatory.yaml”: no matches for kind “Deployment” in version “extensions/v1beta1”
解决方法, 修改mandatory.yarml文件
将apiVersion: extensions/v1beta1 修改成 apiVersion: apps/v1
再次执行
kubectl apply -f mandatory.yaml
正常
访问nodeport看看是否有返回信息
http://192.168.43.152:32080/
测试阶段
配置个服务
[root@ck8s1 ingress]# cat ingress-deploy-demon.yaml
apiVersion: v1
kind: Service
metadata:
name: csctbb
namespace: default
spec:
selector:
app: csctbb
release: canary
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: csctbb-deploy
spec:
replicas: 5
selector:
matchLabels:
app: csctbb
release: canary
template:
metadata:
labels:
app: csctbb
release: canary
spec:
containers:
- name: csctbb
image: ikubernetes/myapp:v2
ports:
- name: httpd
containerPort: 80
配置ingress
[root@ck8s1 ingress]# cat ingress-test.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-csctbb
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: csctbb.csctbb.com
http:
paths:
- path:
backend:
serviceName: csctbb
servicePort: 80
部署服务
[root@ck8s1 ingress]# kubectl apply -f ingress-deploy-demon.yaml
service/csctbb created
deployment.apps/csctbb-deploy created
[root@ck8s1 ingress]# kubectl apply -f ingress-test.yaml
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.extensions/ingress-csctbb created
查看ingress
[root@ck8s1 ingress]# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-csctbb csctbb.csctbb.com 80 22s
配置host访问
192.168.43.1 csctbb.csctbb.com
完成 !
更多推荐
所有评论(0)