|NO.Z.00256|——————————|CloudNative|——|KuberNetes&中介軟體容器化及helm.V03|------------------------------------------|中介軟體.v03|redis.v5.0.4|yaml檔案部署|
阿新 • • 發佈:2022-03-31
[CloudNative:KuberNetes&中介軟體容器化及helm.V03] [Applications.KuberNetes] [|容器化中介軟體基本說明|如何部署一個容器到k8s中|k8s下同步docker映象|部署redis-operator|redis.v5.0.4|]
一、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### --- 建立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單節點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
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)