kubectl create namespace metallb-system
#kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
kubectl apply -f config.yaml
#config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.215.100-192.168.215.199 #改成IP分配的范围
kubectl apply -f metallb.yaml
kubectl get pods -n metallb-system
安装成功如下图,我们可以看到LoadBalancer类型的service获取到外部地址
kubectl apply -f deploy.yaml #deploy.yaml我把镜像传到阿里云镜像服务器,不然国外镜像无法访问
#nginx-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
spec:
ingressClassName: "nginx" #这个参数没有的ingress将分配不到IP
rules:
- host: test.wxy.kim
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
kubectl create secret tls wxy-secret --cert=/root/cert/fullchain.pem --key=/root/cert/privkey.pem
# nginx-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
spec:
ingressClassName: "nginx" #这个参数没有的ingress将分配不到IP
tls:
- hosts:
- test.wxy.kim
secretName: wxy-secret
rules:
- host: test.wxy.kim #你的域名
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80