The basic use of the package manager helm in container choreography system k8s

Linux-1874 2021-01-21 02:46:15
basic use package manager helm


We have learned about k8s Upper hpa Use of resources , Please refer to :https://www.cnblogs.com/qiuhom-1874/p/14293237.html; Today, let's talk about k8s Package manager helm Related topics of ;

helm What is it? ?

If we put k8s The list of resources is analogous to centos Upper rpm package , that helm It's like yum; In short helm Just like that. yum Such a package manager , It enables us to k8s The application becomes simple , We need to deploy some applications to k8s On , We use it directly helm One click deployment can be completed ; With helm Tools , We don't even need to write a list of resources ; about helm Come on , It just passes the list of resources needed by the corresponding application through the template engine , After assigning a value to the corresponding resource list , Send to k8s For application , So as to deploy the application to k8s On ; We'll deploy to k8s The application on is called release; After rendering the template resource list through the template engine , Deploy to k8s It's called a release; Where does the template file come from ? Like rpm Warehouse , The template file here is also from the warehouse , In short helm The warehouse is used to store the template list packing files of various applications , We call this package file chart, namely helm The warehouse is also called chart Warehouse , It is mainly used to store packaged files of various applications ; A package file is mainly chart.yaml,README.md,templates Catalog ,values.yaml; among chart.yaml The file is mainly used to correspond to the metadata information of the application ;README.md It is mainly used to describe the chart How do you use it? , Deployment and so on ;templates Directory is used to store various resource template files ;templates There is an important file in the directory NOTES.txt, This file is also a template file , The main function is to correspond chart The information of successful installation will be output to users after rendering by template engine , Tell users how to use correspondence chart;vlues.yaml The file is mainly used to store the chart The default value of the template , The user does not specify , The value in its internal template is the corresponding values.yaml Value ; Precisely because chart The list of template resources is stored in , Enables users to customize value.yaml file , By specifying custom value.yaml To implement custom chart Purpose ;

helm Installation of tools for

helm 2 It's a little bit of a hassle to deploy , In the early helm2 It's made up of two components , The first is the command line tool helm, The second is k8s Upper tiller Pod;tiller Server side , Mainly accept helm Send to chart, Then from tiller contact apiserver Make a correspondence chart Deployment of ; Now? helm The version is 3.0+, For the former helm2 The way ,helm3 simplified , namely helm No longer dependent on tiller This component , It can be directly connected with apiserver Interact , To the corresponding chart Deploy to k8s On ; Use helm3 The premise is that the corresponding host can connect normally k8s Of apiserver, And the corresponding host has kubectl command , That is, the corresponding host must be able to use kubectl Command to manage the corresponding k8s colony ; The reason is helm It will use kubectl The authentication information of the tool goes to apiserver Interact ;

One 、helm3 Installation

Download binary package

[root@master01 ~]# mkdir helm
[root@master01 ~]# cd helm/
[root@master01 helm]# wget https://get.helm.sh/helm-v3.5.0-linux-amd64.tar.gz
--2021-01-20 21:10:33-- https://get.helm.sh/helm-v3.5.0-linux-amd64.tar.gz
Resolving get.helm.sh (get.helm.sh)... 152.195.19.97, 2606:2800:11f:1cb7:261b:1f9c:2074:3c
Connecting to get.helm.sh (get.helm.sh)|152.195.19.97|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12327633 (12M) [application/x-tar]
Saving to: ‘helm-v3.5.0-linux-amd64.tar.gz’
100%[==================================================================================================================================>] 12,327,633 9.17MB/s in 1.3s
2021-01-20 21:10:35 (9.17 MB/s) - ‘helm-v3.5.0-linux-amd64.tar.gz’ saved [12327633/12327633]
[root@master01 helm]#ls
helm-v3.5.0-linux-amd64.tar.gz
[root@master01 helm]

Unzip the package

[root@master01 helm]# tar xf helm-v3.5.0-linux-amd64.tar.gz
[root@master01 helm]# ls
helm-v3.5.0-linux-amd64.tar.gz linux-amd64
[root@master01 helm]# cd linux-amd64/
[root@master01 linux-amd64]# ls
helm LICENSE README.md
[root@master01 linux-amd64]#

Copy helm Binary file to path Environment variable directory

[root@master01 linux-amd64]# cp helm /usr/bin/
[root@master01 linux-amd64]# hel
helm help
[root@master01 linux-amd64]# hel

Two 、helm Use

see helm edition

[root@master01 ~]# helm version
version.BuildInfo{Version:"v3.5.0", GitCommit:"32c22239423b3b4ba6706d450bd044baffdcf9e6", GitTreeState:"clean", GoVersion:"go1.15.6"}
[root@master01 ~]#

see helm help

[root@master01 ~]# helm -h
The Kubernetes package manager
Common actions for Helm:
- helm search: search for charts
- helm pull: download a chart to your local directory to view
- helm install: upload the chart to Kubernetes
- helm list: list releases of charts
Environment variables:
| Name | Description |
|------------------------------------|-----------------------------------------------------------------------------------|
| $HELM_CACHE_HOME | set an alternative location for storing cached files. |
| $HELM_CONFIG_HOME | set an alternative location for storing Helm configuration. |
| $HELM_DATA_HOME | set an alternative location for storing Helm data. |
| $HELM_DEBUG | indicate whether or not Helm is running in Debug mode |
| $HELM_DRIVER | set the backend storage driver. Values are: configmap, secret, memory, postgres |
| $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use. |
| $HELM_MAX_HISTORY | set the maximum number of helm release history. |
| $HELM_NAMESPACE | set the namespace used for the helm operations. |
| $HELM_NO_PLUGINS | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins. |
| $HELM_PLUGINS | set the path to the plugins directory |
| $HELM_REGISTRY_CONFIG | set the path to the registry config file. |
| $HELM_REPOSITORY_CACHE | set the path to the repository cache directory |
| $HELM_REPOSITORY_CONFIG | set the path to the repositories file. |
| $KUBECONFIG | set an alternative Kubernetes configuration file (default "~/.kube/config") |
| $HELM_KUBEAPISERVER | set the Kubernetes API Server Endpoint for authentication |
| $HELM_KUBECAFILE | set the Kubernetes certificate authority file. |
| $HELM_KUBEASGROUPS | set the Groups to use for impersonation using a comma-separated list. |
| $HELM_KUBEASUSER | set the Username to impersonate for the operation. |
| $HELM_KUBECONTEXT | set the name of the kubeconfig context. |
| $HELM_KUBETOKEN | set the Bearer KubeToken used for authentication. |
Helm stores cache, configuration, and data based on the following configuration order:
- If a HELM_*_HOME environment variable is set, it will be used
- Otherwise, on systems supporting the XDG base directory specification, the XDG variables will be used
- When no other location is set a default location will be used based on the operating system
By default, the default directories depend on the Operating System. The defaults are listed below:
| Operating System | Cache Path | Configuration Path | Data Path |
|------------------|---------------------------|--------------------------------|-------------------------|
| Linux | $HOME/.cache/helm | $HOME/.config/helm | $HOME/.local/share/helm |
| macOS | $HOME/Library/Caches/helm | $HOME/Library/Preferences/helm | $HOME/Library/helm |
| Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm |
Usage:
helm [command]
Available Commands:
completion generate autocompletion scripts for the specified shell
create create a new chart with the given name
dependency manage a chart's dependencies
env helm client environment information
get download extended information of a named release
help Help about any command
history fetch release history
install install a chart
lint examine a chart for possible issues
list list releases
package package a chart directory into a chart archive
plugin install, list, or uninstall Helm plugins
pull download a chart from a repository and (optionally) unpack it in local directory
repo add, list, remove, update, and index chart repositories
rollback roll back a release to a previous revision
search search for a keyword in charts
show show information of a chart
status display the status of the named release
template locally render templates
test run tests for a release
uninstall uninstall a release
upgrade upgrade a release
verify verify that a chart at the given path has been signed and is valid
version print the client version information
Flags:
--debug enable verbose output
-h, --help help for helm
--kube-apiserver string the address and the port for the Kubernetes API server
--kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--kube-as-user string username to impersonate for the operation
--kube-ca-file string the certificate authority file for the Kubernetes API server connection
--kube-context string name of the kubeconfig context to use
--kube-token string bearer token used for authentication
--kubeconfig string path to the kubeconfig file
-n, --namespace string namespace scope for this request
--registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
--repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
--repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
Use "helm [command] --help" for more information about a command.
[root@master01 ~]#

View the list of warehouses

[root@master01 ~]# helm repo -h
This command consists of multiple subcommands to interact with chart repositories.
It can be used to add, remove, list, and index chart repositories.
Usage:
helm repo [command]
Available Commands:
add add a chart repository
index generate an index file given a directory containing packaged charts
list list chart repositories
remove remove one or more chart repositories
update update information of available charts locally from chart repositories
Flags:
-h, --help help for repo
Global Flags:
--debug enable verbose output
--kube-apiserver string the address and the port for the Kubernetes API server
--kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--kube-as-user string username to impersonate for the operation
--kube-ca-file string the certificate authority file for the Kubernetes API server connection
--kube-context string name of the kubeconfig context to use
--kube-token string bearer token used for authentication
--kubeconfig string path to the kubeconfig file
-n, --namespace string namespace scope for this request
--registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
--repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
--repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
Use "helm repo [command] --help" for more information about a command.
[root@master01 ~]# helm repo list
Error: no repositories to show
[root@master01 ~]#

Tips : Here's a hint that we don't have a warehouse ;

Add warehouse

[root@master01 ~]# helm repo add stable https://charts.helm.sh/stable
"stable" has been added to your repositories
[root@master01 ~]# helm repo list
NAME URL
stable https://charts.helm.sh/stable
[root@master01 ~]#

Tips : To add a warehouse, you need to connect to the corresponding warehouse , If your server can't connect to the corresponding warehouse normally , Please use the proxy , The specific way of agency is corresponding to shell Terminal use HTTPS_PROXY The environment variable gives a proxy address that can be used ; Such as HTTPS_PROXY="http://www.ik8s.io:10080", When you use proxy environment variables, you need to pay attention to giving out the corresponding address that does not need proxy , For example, a local address can be used without a proxy NO_PROXY="127.0.0.0/8,192.168.0.0/24"; Otherwise we use kubectl It will proxy to our given proxy address ;

Search for chart

Tips :helm search repo Indicates to list all the added warehouses chart;

Search the warehouse for redis

[root@master01 ~]# helm search repo redis
NAME CHART VERSION APP VERSION DESCRIPTION
stable/prometheus-redis-exporter 3.5.1 1.3.4 DEPRECATED Prometheus exporter for Redis metrics
stable/redis 10.5.7 5.0.7 DEPRECATED Open source, advanced key-value stor...
stable/redis-ha 4.4.6 5.0.6 DEPRECATED - Highly available Kubernetes implem...
stable/sensu 0.2.5 0.28 DEPRECATED Sensu monitoring framework backed by...
[root@master01 ~]#

install stable/redis

[root@master01 ~]# helm install redis-demo stable/redis
WARNING: This chart is deprecated
NAME: redis-demo
LAST DEPLOYED: Wed Jan 20 22:27:18 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This Helm chart is deprecated
Given the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Redis Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/).
The Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping here these years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`)
```bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm install my-release bitnami/<chart> # Helm 3
$ helm install --name my-release bitnami/<chart> # Helm 2
```
To update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute
```bash $ helm
repo add bitnami https://charts.bitnami.com/bitnami
$ helm upgrade my-release bitnami/<chart>
```
Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion.
** Please be patient while the chart is being deployed **
Redis can be accessed via port 6379 on the following DNS names from within your cluster:
redis-demo-master.default.svc.cluster.local for read/write operations
redis-demo-slave.default.svc.cluster.local for read-only operations
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace default redis-demo -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis server:
1. Run a Redis pod that you can use as a client:
kubectl run --namespace default redis-demo-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash
2. Connect using the Redis CLI:
redis-cli -h redis-demo-master -a $REDIS_PASSWORD
redis-cli -h redis-demo-slave -a $REDIS_PASSWORD
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/redis-demo-master 6379:6379 &
redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD
[root@master01 ~]#

see release

[root@master01 ~]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
redis-demo default 1 2021-01-20 22:27:18.635916075 +0800 CST deployed redis-10.5.7 5.0.7
[root@master01 ~]#

verification : use kubectl Tool View k8s The corresponding on the cluster redis-demo Whether to run ?

[root@master01 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-779867bcfc-57zw7 1/1 Running 1 2d7h
myapp-779867bcfc-657qr 1/1 Running 1 2d7h
podinfo-56874dc7f8-5rb9q 1/1 Running 1 2d2h
podinfo-56874dc7f8-t6jgn 1/1 Running 1 2d2h
[root@master01 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11d
myapp-svc NodePort 10.111.14.219 <none> 80:31154/TCP 2d7h
podinfo NodePort 10.111.10.211 <none> 9898:31198/TCP 2d2h
redis-demo-headless ClusterIP None <none> 6379/TCP 18m
redis-demo-master ClusterIP 10.100.228.32 <none> 6379/TCP 18m
redis-demo-slave ClusterIP 10.109.46.121 <none> 6379/TCP 18m
[root@master01 ~]# kubectl get sts
NAME READY AGE
redis-demo-master 0/1 18m
redis-demo-slave 0/2 18m
[root@master01 ~]#

Tips : use kubectl Tool View pod list , No correspondence was found pod function , But the corresponding svc and sts All created normally ;

see pod There is no reason to create

[root@master01 ~]# kubectl describe sts/redis-demo-master|grep -A 10 Events
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 14m (x12 over 14m) statefulset-controller create Pod redis-demo-master-0 in StatefulSet redis-demo-master failed error: failed to create PVC redis-data-redis-demo-master-0: persistentvolumeclaims "redis-data-redis-demo-master-0" is forbidden: exceeded quota: quota-storage-demo, requested: requests.storage=8Gi, used: requests.storage=0, limited: requests.storage=5Gi
Warning FailedCreate 3m40s (x18 over 14m) statefulset-controller create Claim redis-data-redis-demo-master-0 for Pod redis-demo-master-0 in StatefulSet redis-demo-master failed error: persistentvolumeclaims "redis-data-redis-demo-master-0" is forbidden: exceeded quota: quota-storage-demo, requested: requests.storage=8Gi, used: requests.storage=0, limited: requests.storage=5Gi
[root@master01 ~]# kubectl describe sts/redis-demo-slave|grep -A 10 Events
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 14m (x12 over 14m) statefulset-controller create Pod redis-demo-slave-0 in StatefulSet redis-demo-slave failed error: failed to create PVC redis-data-redis-demo-slave-0: persistentvolumeclaims "redis-data-redis-demo-slave-0" is forbidden: exceeded quota: quota-storage-demo, requested: requests.storage=8Gi, used: requests.storage=0, limited: requests.storage=5Gi
Warning FailedCreate 3m41s (x18 over 14m) statefulset-controller create Claim redis-data-redis-demo-slave-0 for Pod redis-demo-slave-0 in StatefulSet redis-demo-slave failed error: persistentvolumeclaims "redis-data-redis-demo-slave-0" is forbidden: exceeded quota: quota-storage-demo, requested: requests.storage=8Gi, used: requests.storage=0, limited: requests.storage=5Gi
[root@master01 ~]#

Tips : Here's a hint that we don't have permission to create , as a result of quota-storage-demo It's forbidden ;

see resourcequota Access control rules

[root@master01 ~]# kubectl get resourcequota
NAME AGE REQUEST LIMIT
quota-storage-demo 19d persistentvolumeclaims: 0/5, requests.ephemeral-storage: 0/1Gi, requests.storage: 0/5Gi limits.ephemeral-storage: 0/2Gi
[root@master01 ~]# kubectl describe resourcequota quota-storage-demo
Name: quota-storage-demo
Namespace: default
Resource Used Hard
-------- ---- ----
limits.ephemeral-storage 0 2Gi
persistentvolumeclaims 0 5
requests.ephemeral-storage 0 1Gi
requests.storage 0 5Gi
[root@master01 ~]#

Tips :resourcequota Access control clearly limits the creation of pvc The sum of the lowest limits is 5G, Create above redis need 8G So it does not meet the corresponding access control rules, so it creates pvc I was rejected , Lead to pod Failed to create ;

uninstall redis-demo

[root@master01 ~]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
redis-demo default 1 2021-01-20 22:27:18.635916075 +0800 CST deployed redis-10.5.7 5.0.7
[root@master01 ~]# helm uninstall redis-demo
release "redis-demo" uninstalled
[root@master01 ~]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
[root@master01 ~]#

Delete resourcequota Access control

[root@master01 ~]# kubectl get resourcequota
NAME AGE REQUEST LIMIT
quota-storage-demo 19d persistentvolumeclaims: 0/5, requests.ephemeral-storage: 0/1Gi, requests.storage: 0/5Gi limits.ephemeral-storage: 0/2Gi
[root@master01 ~]# kubectl delete resourcequota/quota-storage-demo
resourcequota "quota-storage-demo" deleted
[root@master01 ~]# kubectl get resourcequota
No resources found in default namespace.
[root@master01 ~]#

Check pv, Is there enough pv?

[root@master01 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv-v1 5Gi RWO,ROX,RWX Retain Bound kube-system/alertmanager 3d22h
nfs-pv-v2 5Gi RWO,ROX,RWX Retain Bound kube-system/prometheus-data-prometheus-0 3d22h
nfs-pv-v3 5Gi RWO,ROX,RWX Retain Available 3d22h
[root@master01 ~]#

Tips : There's another pv Not used , But the size is just 5g Not enough redis Use ;

establish pv

[root@master01 ~]# cat pv-demo.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv-v4
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes: ["ReadWriteOnce","ReadWriteMany","ReadOnlyMany"]
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /data/v4
server: 192.168.0.99
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv-v5
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes: ["ReadWriteOnce","ReadWriteMany","ReadOnlyMany"]
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /data/v5
server: 192.168.0.99
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv-v6
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes: ["ReadWriteOnce","ReadWriteMany","ReadOnlyMany"]
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /data/v6
server: 192.168.0.99
[root@master01 ~]# kubectl apply -f pv-demo.yaml
persistentvolume/nfs-pv-v4 created
persistentvolume/nfs-pv-v5 created
persistentvolume/nfs-pv-v6 created
[root@master01 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv-v1 5Gi RWO,ROX,RWX Retain Bound kube-system/alertmanager 3d22h
nfs-pv-v2 5Gi RWO,ROX,RWX Retain Bound kube-system/prometheus-data-prometheus-0 3d22h
nfs-pv-v3 5Gi RWO,ROX,RWX Retain Available 3d22h
nfs-pv-v4 10Gi RWO,ROX,RWX Retain Available 3s
nfs-pv-v5 10Gi RWO,ROX,RWX Retain Available 3s
nfs-pv-v6 10Gi RWO,ROX,RWX Retain Available 3s
[root@master01 ~]#

reinstall redis

[root@master01 ~]# helm install redis-demo stable/redis
WARNING: This chart is deprecated
NAME: redis-demo
LAST DEPLOYED: Wed Jan 20 22:54:30 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This Helm chart is deprecated
Given the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Redis Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/).
The Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping here these years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`)
```bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm install my-release bitnami/<chart> # Helm 3
$ helm install --name my-release bitnami/<chart> # Helm 2
```
To update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute
```bash $ helm
repo add bitnami https://charts.bitnami.com/bitnami
$ helm upgrade my-release bitnami/<chart>
```
Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion.
** Please be patient while the chart is being deployed **
Redis can be accessed via port 6379 on the following DNS names from within your cluster:
redis-demo-master.default.svc.cluster.local for read/write operations
redis-demo-slave.default.svc.cluster.local for read-only operations
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace default redis-demo -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis server:
1. Run a Redis pod that you can use as a client:
kubectl run --namespace default redis-demo-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash
2. Connect using the Redis CLI:
redis-cli -h redis-demo-master -a $REDIS_PASSWORD
redis-cli -h redis-demo-slave -a $REDIS_PASSWORD
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/redis-demo-master 6379:6379 &
redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD
[root@master01 ~]#

Again using kubectl Tool to see the corresponding pod Is it working ?

[root@master01 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-779867bcfc-57zw7 1/1 Running 1 2d7h
myapp-779867bcfc-657qr 1/1 Running 1 2d7h
podinfo-56874dc7f8-5rb9q 1/1 Running 1 2d2h
podinfo-56874dc7f8-t6jgn 1/1 Running 1 2d2h
redis-demo-master-0 0/1 CrashLoopBackOff 4 2m33s
redis-demo-slave-0 0/1 CrashLoopBackOff 4 2m33s
[root@master01 ~]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
redis-data-redis-demo-master-0 Bound nfs-pv-v4 10Gi RWO,ROX,RWX 2m39s
redis-data-redis-demo-slave-0 Bound nfs-pv-v6 10Gi RWO,ROX,RWX 2m39s
[root@master01 ~]#

Tips : here pvc Automatic creation succeeded , But it corresponds to pod Can start normally ;

see pod details

[root@master01 ~]# kubectl describe pod/redis-demo-master-0|grep -A 10 Events
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m53s default-scheduler Successfully assigned default/redis-demo-master-0 to node01.k8s.org
Normal Pulling 6m51s kubelet Pulling image "docker.io/bitnami/redis:5.0.7-debian-10-r32"
Normal Pulled 6m33s kubelet Successfully pulled image "docker.io/bitnami/redis:5.0.7-debian-10-r32" in 18.056248477s
Normal Started 5m47s (x4 over 6m33s) kubelet Started container redis-demo
Normal Created 5m1s (x5 over 6m33s) kubelet Created container redis-demo
Normal Pulled 5m1s (x4 over 6m32s) kubelet Container image "docker.io/bitnami/redis:5.0.7-debian-10-r32" already present on machine
Warning BackOff 100s (x28 over 6m31s) kubelet Back-off restarting failed container
[root@master01 ~]# kubectl describe pod/redis-demo-slave-0|grep -A 10 Events
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 6m58s (x2 over 6m58s) default-scheduler 0/5 nodes are available: 5 pod has unbound immediate PersistentVolumeClaims.
Normal Scheduled 6m55s default-scheduler Successfully assigned default/redis-demo-slave-0 to node01.k8s.org
Normal Pulling 6m55s kubelet Pulling image "docker.io/bitnami/redis:5.0.7-debian-10-r32"
Normal Pulled 6m37s kubelet Successfully pulled image "docker.io/bitnami/redis:5.0.7-debian-10-r32" in 17.603521415s
Normal Created 5m12s (x5 over 6m37s) kubelet Created container redis-demo
Normal Started 5m12s (x5 over 6m37s) kubelet Started container redis-demo
Normal Pulled 5m12s (x4 over 6m36s) kubelet Container image "docker.io/bitnami/redis:5.0.7-debian-10-r32" already present on machine
Warning BackOff 106s (x27 over 6m35s) kubelet Back-off restarting failed container
[root@master01 ~]#

Tips : Here's the corresponding pod And the details don't tell you exactly what's wrong ; All in all pod Not working properly ( The estimation is related to the corresponding mirror startup ); Through the above experiments, although pod Not working properly , however helm Be able to put the corresponding chart Submit to k8s function ;helm Our mission is to succeed ;

uninstall redis-demo, Look again chart Try to install it

Tips : Search here stable Warehouse redis, In the warehouse redis Of chart They're all obsolete versions ;

Delete repository , Re add warehouse

[root@master01 ~]# helm repo list
NAME URL
stable https://charts.helm.sh/stable
[root@master01 ~]# helm repo remove stable
"stable" has been removed from your repositories
[root@master01 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
[root@master01 ~]# helm repo list
NAME URL
bitnami https://charts.bitnami.com/bitnami
[root@master01 ~]#

Search for redis chart

[root@master01 ~]# helm search repo redis
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/redis 12.6.2 6.0.10 Open source, advanced key-value store. It is of...
bitnami/redis-cluster 4.2.6 6.0.10 Open source, advanced key-value store. It is of...
[root@master01 ~]#

install bitnami/redis

[root@master01 ~]# helm install redis-demo bitnami/redis
NAME: redis-demo
LAST DEPLOYED: Thu Jan 21 01:58:18 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
Redis can be accessed via port 6379 on the following DNS names from within your cluster:
redis-demo-master.default.svc.cluster.local for read/write operations
redis-demo-slave.default.svc.cluster.local for read-only operations
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace default redis-demo -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis(TM) server:
1. Run a Redis(TM) pod that you can use as a client:
kubectl run --namespace default redis-demo-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis:6.0.10-debian-10-r1 -- bash
2. Connect using the Redis(TM) CLI:
redis-cli -h redis-demo-master -a $REDIS_PASSWORD
redis-cli -h redis-demo-slave -a $REDIS_PASSWORD
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/redis-demo-master 6379:6379 &
redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD
[root@master01 ~]#

see pod Operation of the

Tips : Here's a hint append-only file No permission to open , It means that the corresponding storage we mount has no write permission ;

Add write permissions to the back end storage

Tips : Here is the permission corresponding to pod Still can't run normally ; Delete pod try , Look at the corresponding pod Whether it will work normally after reconstruction ?

[root@master01 ~]# kubectl delete pod --all
pod "redis-demo-master-0" deleted
pod "redis-demo-slave-0" deleted
[root@master01 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-demo-master-0 0/1 ContainerCreating 0 3s
redis-demo-slave-0 0/1 Running 0 3s
[root@master01 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-demo-master-0 0/1 Running 0 5s
redis-demo-slave-0 0/1 Running 0 5s
[root@master01 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-demo-master-0 1/1 Running 0 62s
redis-demo-slave-0 1/1 Running 0 62s
redis-demo-slave-1 0/1 CrashLoopBackOff 2 26s
[root@master01 ~]#

Tips : Delete... Here pod in the future , New pod It's going to work ; But there's one more slave Run failed , It should be because the back-end storage doesn't have write permission ;

Add write permission to the back end storage again

Tips : You can see that adding write permission to the corresponding directory , Corresponding pod It's working ;

Get into redis Primary and secondary replication clusters

Tips : You can see in the master Node , You can see the information corresponding to the two slave nodes ;

verification : Write data on master node , See if the corresponding slave node can synchronize data ?

Tips : You can see in the master End write data ,slave The end can synchronize the corresponding data normally , stay slave The end can get the corresponding data normally , This indicates that the master-slave replication cluster works normally ;

Update warehouse

[root@master01 ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
[root@master01 ~]#

Tips : It is recommended to update the warehouse every time a new application is deployed , And then deploy the application ;

Deploy applications with custom information

Tips : The above command is given by --set Option to transfer custom information to the corresponding chart in , Used to replace the values in the corresponding template file ; The above command indicates setting redis The password for admin123.com,master and slave No persistent storage function is turned on ( Production environment is not recommended ); Of course, the simple setting of individual parameters can be used --set To specify the , If the parameters are too complex , It is recommended to use value.yaml File to replace , Use --value Option to specify the corresponding value file ;

版权声明
本文为[Linux-1874]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121024545722y.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云