其他分享
首页 > 其他分享> > kubernetes第五天endpoints

kubernetes第五天endpoints

作者:互联网

kubernetes第五天endpoints

1、EndPoints

收录Pod。也可以说叫管理pod
#创建Service,还会自动创建一个同名的Endpoints。

Service只负责提供一个VIP,EndPoints才是提供负载均衡服务的。 类型ExternalName不可以定义端口和https(证书)

将外部的服务接入集群:
---
kind: Endpoints
apiVersion: v1
metadata:
  name: mysql
subsets:#存活性监测
  - addresses: # 成功的ip
      - ip: 192.168.11.101
    ports:
      - port: 33060
---
kind: Service
apiVersion: v1
metadata:
  name: mysql
spec:
  ports:
    - port: 3306  #端口
      targetPort: 33060

2、Ingress(域名代理)

Ingress
	Nginx Ingress  # 底层是nginx
	Treaket  #性能差
	Istio #有点难


#查看是否启动成功
kubectl get pods -n ingress-nginx 


---
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: django
spec:
  rules: #规则
    - host: www.django.com
      http:
        paths: #访问路径
          - backend: #后端
              serviceName: django
              servicePort: 80
            path: /

# 错误之后,默认跳转的后端
nginx.ingress.kubernetes.io/custom-http-errors: "404,415,500,502"
nginx.ingress.kubernetes.io/default-backend: error

# 永久性重定向
nginx.ingress.kubernetes.io/permanent-redirect: https://www.baidu.com

# 最大链接数
nginx.ingress.kubernetes.io/global-rate-limit: 1

# 白名单
nginx.ingress.kubernetes.io/whitelist-source-range: 192.168.11.102

# 自定义配置
nginx.ingress.kubernetes.io/configuration-snippet: |
    deny 192.168.102;
    allow all;

3、DaemonSet

每一个节点有且只有一个pod,都只是部署一个Pod
#新增节点会自动新增pod  删除节点会自动删除一个pod
收集日志
监控

---
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: daemonset
spec:
  selector:
    matchLabels:
      app: daemonset
  template:
    metadata:
      labels:
        app: daemonset
    spec:
      containers:
        - name: nginx
          image: nginx
[root@k8s-master-01 k8s]# kubectl set image daemonset/daemonset nginx=nginx:1.19
daemonset.apps/daemonset image updated

4、StatefulSet

有状态集合。启动有顺序

是用在有状态的架构之中。

#依赖servies

MySQL

---
kind: Service
apiVersion: v1
metadata:
  name: statefulset
spec:
  selector:
    app: statefulset
  ports:
    - port: 80
      targetPort: 80
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: statefulset
spec:
  selector:
    matchLabels:
      app: statefulset
  serviceName: statefulset
  template:
    metadata:
      labels:
        app: statefulset
    spec:
      containers:
        - name: nginx
          image: nginx

5、Job

只执行一次。
---
kind: Job
apiVersion: batch/v1
metadata:
  name: job
spec:
  template:
    metadata:
      labels:
        app: job
    spec:
      #只能是never 或者 OnFailure
      restartPolicy: OnFailure
      containers:
        - name: mysql
          image: mysql:5.7
          command:
            - "/bin/sh"
            - "-c"
            - "mysql -uroot -hmysql.mysql.svc.cluster.local -p123456 -e 'select sleep(20);'"



6、cronJob

定时执行Job

---
kind: CronJob
apiVersion: batch/v1beta1
metadata:
  name: cronjob
spec:
  jobTemplate:
    metadata:
      labels:
        app: cronjob
    spec:
      template:
        metadata:
          labels:
            app: cronjob
        spec:
         #只能是never 或者 OnFailure
          restartPolicy: OnFailure
          containers:
            - name: mysql
              image: mysql:5.7
              command:
                - "/bin/sh"
                - "-c"
                - "mysql -uroot -hmysql.mysql.svc.cluster.local -p123456 -e 'select sleep(20);'"
  schedule: '* * * * *'

标签:name,kubernetes,app,nginx,mysql,第五天,endpoints,spec,metadata
来源: https://www.cnblogs.com/1617271856qq/p/15781456.html