{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
安装前需要选择兼容你Kubernetes的版本,不能会失败。
ingress由两部分组成:
以下就是具体的安装步骤:
Ingress Controller 是负责处理 Ingress 请求的组件。Kubernetes 提供了多种 Ingress Controller,您可以根据需要选择。以下是常用的 Ingress Controller:
在本教程中,我们将使用 Nginx Ingress Controller 进行演示。
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml
一定要把版本后面带的@摘要值删除掉。
要创建 Ingress 资源对象,您可以使用 kubectl 命令:
kubectl apply -f deploy.yaml
#安装后查看安装结果
kubectl get pods -n ingress-nginx
看到下图的结果就代表成功了,只要controller是Running,其它是Completed就可以了。
如果发现安装失败,可以尝试删除pod再重新kubectl apply -f deploy.yaml。
#强制删除pod
kubectl delete pod --all -n ingress-nginx --force --grace-period=0
kubectl apply -f deploy.yaml
如果想查看具体的失败原因,可以使用下面的命令。
kubectl get pods -n ingress-nginx
kubectl describe pod ingress-nginx-controller-6c978d4999-vqfwp --namespace ingress-nginx
vim nginx-deploy.yaml:
apiVersion: apps/v1
kind: Deployment metadata: labels: app: nginx-demo
name: nginx-demo
spec: replicas: 2 selector: matchLabels: app: nginx
template: metadata: labels: app: nginx
spec: containers: - image: nginx
name: nginx --- apiVersion: v1
kind: Service metadata: labels: app: nginx
name: nginx
spec: selector: app: nginx
ports: - port: 8000 protocol: TCP
targetPort: 80
kubecl apply -f nginx-deploy.yaml
kubectl get pod,svc
vim ingress-nginx.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx
spec:
ingressClassName: nginx
rules:
- host: "demo.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: nginx
port:
number: 8000
没有域名可以自己在/etc/hosts 增加demo.com:
kubecl apply -f ingress-nginx.yaml
kubectl get ing
查看端口:
kubectl get pods,svc -n ingress-nginx
一般安装都会失败,主要是国内无法下载镜像。可以看到第一个deploy.yaml中要下载两个镜像文件分别是:
有几种解决方案:
docker tag old_image_name new_image_name