0.K8S集群环境
Kubernetes v1.16.6
traefik v2.0.7
1.部署服务
文件名: my-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 2
selector:
matchLabels:
app: my-nginx
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:1.7.9
ports:
- containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: my-nginx
spec:
selector:
app: my-nginx
ports:
- protocol: TCP
port: 80
$ kubectl create -f my-nginx.yaml
deployment.apps/my-nginx created
service/my-nginx created
查看部署情况
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx ClusterIP 10.254.31.23 <none> 80/TCP 29h
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
my-nginx-86575b68dc-dt8wr 1/1 Running 0 72s
my-nginx-86575b68dc-ltlv2 1/1 Running 0 72s
2.配置 域名访问
文件名: my-nginx-ingess.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: my-nginx
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`k8s-test.linuxhub.cn`)
kind: Rule
services:
- name: my-nginx
port: 80
$ kubectl apply -f my-nginx-ingess.yaml
ingressroute.traefik.containo.us/my-nginx created
查看部署情况
$ kubectl get IngressRoute
NAME AGE
my-nginx 3m18s
3.域名访问
http://k8s-test.linuxhub.cn
网友评论