CC00256.CloudKubernetes——|KuberNetes&中间件容器化及helm.V03|——|中间件.v03|redis.v5.0.4|yaml文件部署|

一、k8s下同步docker镜像
### --- 在节点1上下载并镜像导入到目标节点

[root@k8s-master01 redis]# scp redis.tar rabbit.tar k8s-master02:/root/
### --- 将镜像导入到docker容器中

[root@k8s-master02 ~]# docker load -i redis.tar
[root@k8s-master02 ~]# docker load -i rabbit.tar
二、通过yaml文件创建redis单节点pod
### --- 创建redis-deployment.yaml注释:

~~~     # replicas: 1   
~~~     副本数量设置为1:因为redis是有状态的应用;若是需要使用多个的话,
~~~     需要搭建一个集群或者主从可以通过这个实例去创建中间件的pod
### --- 创建redis-deployment.yaml配置文件

[root@k8s-master01 redis]# cat redis.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis-single-node
  name: redis-single-node
  namespace: ratel-test1
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: redis-single-node
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: redis-single-node
    spec:
      containers:
      - command:
        - sh
        - -c
        - redis-server 
        - /mnt/redis.conf
        env:
        - name: TZ
          value: Asia/Shanghai
        - name: LANG
          value: C.UTF-8
        image: redis:5.0.4-alpine
        imagePullPolicy: IfNotPresent
        lifecycle: {}
        livenessProbe:
          failureThreshold: 2
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 6379
          timeoutSeconds: 2
        name: redis-single-node
        ports:
        - containerPort: 6379
          name: web
          protocol: TCP
        readinessProbe:
          failureThreshold: 2
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 6379
          timeoutSeconds: 2
        resources:
          limits:
            cpu: 100m
            memory: 339Mi
          requests:
            cpu: 10m
            memory: 10Mi
        securityContext:
          privileged: false
          runAsNonRoot: false
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/zoneinfo/Asia/Shanghai
          name: tz-config
        - mountPath: /etc/localtime
          name: tz-config
        - mountPath: /etc/timezone
          name: timezone
        - mountPath: /mnt
          name: redis-conf
          readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      tolerations:
      - effect: NoExecute
        key: node.kubernetes.io/unreachable
        operator: Exists
        tolerationSeconds: 30
      - effect: NoExecute
        key: node.kubernetes.io/not-ready
        operator: Exists
        tolerationSeconds: 30
      volumes:
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
          type: ""
        name: tz-config
      - hostPath:
          path: /etc/timezone
          type: ""
        name: timezone
      - configMap:
          defaultMode: 420
          name: redis-conf
        name: redis-conf
三、创建redis-deployment
### --- 创建redis单节点pod

[root@k8s-master01 redis]# kubectl create -f redis.yaml -n ratel-test1
### --- 注意:
~~~     在创建service名称的时候,不要和redis的pod的名称一致,可以使用项目的名称去命名
~~~     若是命名一致,可能会出现问题。
~~~     在部署项目的时候,可能是一个项目用一个redis,或多个项目用一个redis,
### --- redis是共用的:

~~~     项目a和项目b各自公用各自的一个redis;这样可以把这个redis单独放在一个namespace下;
~~~     用来放公共服务的namespace下,项目可以去连接各自的redis
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值