k8s 安装redis-operator并以operator方式部署redis-standalone redis-cluster集群完整操作记录
安裝redis-operator
install.sh
[root@linux:redis-operator]$ cat install.sh #!/usr/bin/env bash# This script is for installing OLM from a GitHub releaseset -edefault_base_url=https://github.com/operator-framework/operator-lifecycle-manager/releases/downloadif [[ ${#@} -lt 1 || ${#@} -gt 2 ]]; thenecho "Usage: $0 version [base_url]"echo "* version: the github release version"echo "* base_url: the github base URL (Default: $default_base_url)"exit 1 fiif kubectl get deployment olm-operator -n openshift-operator-lifecycle-manager > /dev/null 2>&1; thenecho "OLM is already installed in a different configuration. This is common if you are not running a vanilla Kubernetes cluster. Exiting..."exit 1 firelease="$1" base_url="${2:-${default_base_url}}" url="${base_url}/${release}" namespace=olmif kubectl get deployment olm-operator -n ${namespace} > /dev/null 2>&1; thenecho "OLM is already installed in ${namespace} namespace. Exiting..."exit 1 fikubectl apply -f "${url}/crds.yaml" kubectl wait --for=condition=Established -f "${url}/crds.yaml" kubectl apply -f "${url}/olm.yaml"# wait for deployments to be ready kubectl rollout status -w deployment/olm-operator --namespace="${namespace}" kubectl rollout status -w deployment/catalog-operator --namespace="${namespace}"retries=30 until [[ $retries == 0 ]]; donew_csv_phase=$(kubectl get csv -n "${namespace}" packageserver -o jsonpath='{.status.phase}' 2>/dev/null || echo "Waiting for CSV to appear")if [[ $new_csv_phase != "$csv_phase" ]]; thencsv_phase=$new_csv_phaseecho "Package server phase: $csv_phase"fiif [[ "$new_csv_phase" == "Succeeded" ]]; thenbreakfisleep 10retries=$((retries - 1)) doneif [ $retries == 0 ]; thenecho "CSV \"packageserver\" failed to reach phase succeeded"exit 1 fikubectl rollout status -w deployment/packageserver --namespace="${namespace}"redis-operator.yaml
[root@linux:redis-operator]$ cat redis-operator.yaml apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata:name: my-redis-operatornamespace: operators spec:channel: stablename: redis-operatorsource: operatorhubio-catalogsourceNamespace: olmInstall redis-operator on Kubernetes
Install Operator Lifecycle Manager (OLM), a tool to help manage the Operators running on your cluster.
$ curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.19.1/install.sh | bash -s v0.19.1Install the operator by running the following command:What happens when I execute this command?
$ kubectl create -f https://operatorhub.io/install/redis-operator.yamlThis Operator will be installed in the “operators” namespace and will be usable from all namespaces in the cluster.
After install, watch your operator come up using next command.
$ kubectl get csv -n operatorsTo use it, checkout the custom resource definitions (CRDs) introduced by this operator to start using it.
部署redis
redis-standalone.yml
[root@linux:redis-operator]$ cat redis-single.yml apiVersion: redis.redis.opstreelabs.in/v1beta1 kind: Redis metadata:name: redis-standalone spec:kubernetesConfig:image: 'quay.io/opstree/redis:v6.2.5'imagePullPolicy: IfNotPresentresources:requests:cpu: 101mmemory: 128Milimits:cpu: 101mmemory: 128MiserviceType: ClusterIPstorage:volumeClaimTemplate:spec:accessModes:- ReadWriteOnceresources:requests:storage: 1GiredisExporter:enabled: falseimage: 'quay.io/opstree/redis-exporter:1.0'redis-cluster.yml
[root@linux:redis-operator]$ cat redis-cluster.yml apiVersion: redis.redis.opstreelabs.in/v1beta1 kind: RedisCluster metadata:name: redis-cluster spec:clusterSize: 3kubernetesConfig:image: 'quay.io/opstree/redis:v6.2.5'imagePullPolicy: IfNotPresentresources:requests:cpu: 101mmemory: 128Milimits:cpu: 101mmemory: 128MiserviceType: ClusterIPredisExporter:enabled: falseimage: 'quay.io/opstree/redis-exporter:1.0'redisLeader:serviceType: ClusterIPredisFollower:serviceType: ClusterIPstorage:volumeClaimTemplate:spec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi執行結果:
[root@linux:redis-operator]$ kubectl get po NAME READY STATUS RESTARTS AGE redis-cluster-follower-0 1/1 Running 0 98s redis-cluster-follower-1 1/1 Running 0 67s redis-cluster-follower-2 1/1 Running 0 35s redis-cluster-leader-0 1/1 Running 0 98s redis-cluster-leader-1 1/1 Running 0 67s redis-cluster-leader-2 1/1 Running 0 35s進入集群,-c集群模式連接:
bash-4.4# redis-cli -c 127.0.0.1:6379> 127.0.0.1:6379> 127.0.0.1:6379> set k1 v1 -> Redirected to slot [12706] located at 172.17.0.13:6379 OK 172.17.0.13:6379> 172.17.0.13:6379> 172.17.0.13:6379> get k1 "v1" 172.17.0.13:6379>參考鏈接:https://operatorhub.io/operator/redis-operator
總結
以上是生活随笔為你收集整理的k8s 安装redis-operator并以operator方式部署redis-standalone redis-cluster集群完整操作记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: docker ctr crictl命令对
- 下一篇: python pip配置镜像源:doub