k8s安装ingress-nginx
k8s安装ingress-nginx的详细步骤master节点:10.6.14.23第一步: 准备yaml文件1,ingress-nginx我们选择0.20.0版本https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0mkdir ingress-nginx#替换defaultbackend-amd64镜像地址sed -i 's#k
·
k8s安装ingress-nginx的详细步骤
master节点: 10.6.14.23
第一步: 准备yaml文件
1,ingress-nginx我们选择0.20.0版本 https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0
mkdir ingress-nginx
#替换defaultbackend-amd64镜像地址
sed -i 's#k8s.gcr.io/defaultbackend-amd64#registry.cn-qingdao.aliyuncs.com/kubernetes_xingej/defaultbackend-amd64#g' mandatory.yaml
#替换nginx-ingress-controller镜像地址
sed -i 's#quay.io/kubernetes-ingress-controller/nginx-ingress-controller#registry.cn-qingdao.aliyuncs.com/kubernetes_xingej/nginx-ingress-controller#g' mandatory.yaml
#修改service-nodeport.yaml
vi 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
第二步: 准备镜像
#在所有的节点上执行
docker pull registry.cn-qingdao.aliyuncs.com/kubernetes_xingej/defaultbackend-amd64:1.5
docker pull registry.cn-qingdao.aliyuncs.com/kubernetes_xingej/nginx-ingress-controller:0.20.0
第三步: 执行部署命令
kubectl create namespace ingress-nginx
kubectl apply -f mandatory.yaml
kubectl apply -f service-nodeport.yaml
# 出现异常:
error: unable to recognize "lzb-test.yaml": no matches for kind "Deployment" in version "extensions/v1beta1"
# 修改mandatory.yarml文件
apiVersion: extensions/v1beta1 修改成 apiVersion: apps/v1
# 查看pod的运行状态
kubectl get pods -n ingress-nginx
#service状态及暴露端口
kubectl get svc -n ingress-nginx
到此安装完成, 输入 http://10.6.14.23:32080/ 如果显示, 则说明安装成功
现在开始配置调转别的服务
新建一个服务
vi deploy-demon.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: default
spec:
selector:
app: myapp
release: canary
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploy
spec:
replicas: 5
selector:
matchLabels:
app: myapp
release: canary
template:
metadata:
labels:
app: myapp
release: canary
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v2
ports:
- name: httpd
containerPort: 80
#部署
kubectl apply -f deploy-demon.yaml
kubectl get pods
测试服务启动成功, 现在开始配置ingress
vi ingress-myapp.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myapp
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: myapp.magedu.com #生产中该域名应当可以被公网解析
http:
paths:
- path:
backend:
serviceName: myapp #这个名称与测试服务的名称相同
servicePort: 80
#启动
kubectl apply -f ingress-myapp.yaml
在本地电脑的hosts配置
10.6.14.23 myapp.magedu.com
http://myapp.magedu.com:32080/
至此安装完成 与测试完成
更多推荐
已为社区贡献3条内容
所有评论(0)