作业创建redis
网络:
1.创建hadless无头服务
2.名称为redis-hadless
存储:
1.使用LocalPV
2.持久化目录/data/k8s/redis-data
3.延迟绑定
4.storageClassName类型local-storage
5.pvc通过storageClassName绑定LocalPV
POD:
1.使用StatefulSets控制器
2.三副本
3.POD名称redis-0,redis-1,redis-2
4.PVC模板使用storageClassName关联LocalPV
5.不需要从节点,只需要三个master即可
6.端口号暴露的是6379
效果:
1.创建三个有序的RedisPOD
2.数据持久化到对应的PV上
3.删除POD,自动重建POD,数据不会丢失,集群正常
配置文件:
1.使用configMap持久化
2.思考配置文件需要什么
Redis集群创建命令:
在宿主机执行即可
redis-cli --cluster reshard 10.0.0.51:6380
--cluster-from all
--cluster-to 1}')
--cluster-slots 4096
--cluster-yes
创建redis目录
创建redis-hadless
使用statefulset部署elasticsearch集群
1.准备环境-两个node节点都操作,master节点不用操作
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -w vm.max_map_count=262144
mkdir -p /data/k8s/es
chmod -R g+rwx /data/k8s/es
chgrp -R 0 /data/k8s/es
chgrp: 改变所属用户组
用法:chgrp -R 用户名 目录/文件
0是root用户
2.创建LocalPV
cat > es-pv.yaml << 'EOF'
apiVersion: v1 #接口版本
kind: PersistentVolume #资源类型为pv
metadata: #创建pv元数据
name: pv-local-node1 #pv元数据名字
spec: #定义pod运行配置
capacity: #pv的容量
storage: 5Gi #存储容量为5G
volumeMode: Filesystem #文件系统为Filesystem
accessModes: #访问类型
- ReadWriteOnce #读写权限,并且只能被单个pod挂载
persistentVolumeReclaimPolicy: Retain #回收策略,保留数据
storageClassName: local-storage #存储类名字
local: #存储路径
path: /data/k8s/es
nodeAffinity: #node亲和性
required: #硬策略
nodeSelectorTerms: #node选择器
- matchExpressions: #匹配规则
- key: kubernetes.io/hostname #键为kubernetes.io/hostname
operator: In #操作in,必须的意思
values:
- node1 #值为node1
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-local-node2
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /data/k8s/es
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node2
EOF
针对 PV 持久卷,Kubernetes 支持两种卷模式(volumeModes):Filesystem(文件系统) 和 Block(块)。
volumeMode 是一个可选的 API 参数。 如果该参数被省略,默认的卷模式是 Filesystem。
volumeMode 属性设置为 Filesystem 的卷会被 Pod 挂载(Mount) 到某个目录。 如果卷的存储来自某块设备而该设备目前为空,Kuberneretes 会在第一次挂载卷之前 在设备上创建文件系统。
3.创建延迟绑定
cat > es-StorageClass.yaml << 'EOF'
apiVersion: storage.k8s.io/v1 #接口类型
kind: StorageClass #资源类型为StorageClass
metadata: #StorageClass的元数据
name: local-storage #StorageClass的名字为 local-storage
provisioner: kubernetes.io/no-provisioner # 我正在使用具有3个副本的PV(kubernetes.io/no-provisioner storageClass)使用本地卷部署StatefulSet。 为两个工作节点都创建了2个PV
volumeBindingMode: WaitForFirstConsumer #等待第一个消费者才绑定
EOF
4.创建无头服务
cat > es-svc.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: es
labels:
app: es
spec:
selector:
app: es
ports:
- name: http
port: 9200
- name: http-cluster
port: 9300
clusterIP: None
EOF
5.创建configmap
cat > es-configmap.yaml << 'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: es-config
data:
elasticsearch.yml: |
cluster.name: es-k8s
network.host: 0.0.0.0
node.name: ${HOSTNAME}
discovery.seed_hosts: es-0.es,es-1.es #相互发现
cluster.initial_master_nodes: es-0 #初始化容器就是自己
EOF
运行每一个es都有一个环境变量
6.创建StatefulSet
cat >es-StatefulSet.yaml<<'EOF'
apiVersion: apps/v1 #接口类型
kind: StatefulSet #资源类型为statefulset
metadata: #statefulset元数据
name: es #statefulset的名字
spec: #定义pod运行的配置
serviceName: es #定义pod运行的名字为es
replicas: 2 #定义pod运行的副本数2
selector: #定义pod运行选择器
matchLabels: #匹配的标签
app: es #标签
template: #创建pod的运行配置模板
metadata: #创建pod 的元数据
labels: #创建pod 的标签
app: es #具体标签app:es
spec: #创建pod中运行的具体配置
volumes: #创建pod中挂载的目录
- name: es-config #名字叫 es-config
configMap: #挂载configMap
name: es-config #下面一块都是configMap
items:
- key: elasticsearch.yml
path: elasticsearch.yml
initContainers:
- name: init-sysctl
image: busybox
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
command: ["sysctl", "-w", "vm.max_map_count=262144"]
containers: #创建容器的具体配置
- name: es #容器名字叫es
image: elasticsearch:7.17.0 #下载镜像
imagePullPolicy: IfNotPresent #镜像下载方式
resources: #资源配置
requests: #最小资源配置
cpu: 500m #cpu500m
memory: 500Mi #内存500M
limits: #最大资源配置
cpu: 1000m #cpu1000m
memory: 1Gi #内存1G
readinessProbe: #就绪探针
httpGet:
path: /_cat/health
port: 9200
initialDelaySeconds: 10
periodSeconds: 10
ports:
- name: http
containerPort: 9200
- name: http-cluster
containerPort: 9300
env:
- name: ES_JAVA_OPTS
value: "-Xms512m -Xmx512m"
volumeMounts:
- name: pvc
mountPath: /usr/share/elasticsearch/data
- name: es-config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
volumeClaimTemplates: #创建pvc
- metadata:
name: pvc
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: local-storage #匹配storage-class名字
EOF
执行
7.创建对外访问的svc
cat > es-svc-cluster.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: es-svc
labels:
app: es-svc
spec:
selector:
app: es
ports:
- name: http
port: 9200
targetPort: 9200 #目标port
EOF
8.创建ingress
cat > es-ingress.yaml << 'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: es-ingress
spec:
rules:
- host: es.k8s.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: es-svc
port:
number: 9200
EOF
注意:要安装ingress
电脑还要配置host解析
电脑访问结果
安装kibana
cat > kibana-all.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: kibana
labels:
k8s-app: kibana
spec:
replicas: 1
selector:
matchLabels:
k8s-app: kibana
template:
metadata:
labels:
k8s-app: kibana
spec:
containers:
- name: kibana
imagePullPolicy: IfNotPresent
image: kibana:7.17.0
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 500m
memory: 1Gi
env:
- name: ELASTICSEARCH_HOSTS #环境变量
value: http://es-svc:9200 #es地址
ports:
- containerPort: 5601
---
apiVersion: v1 #kibana的svc
kind: Service
metadata:
name: kibana-svc
spec:
ports:
- port: 5601
protocol: TCP
targetPort: kibana-port
selector:
k8s-app: kibana
---
apiVersion: networking.k8s.io/v1 #kibana的ingress
kind: Ingress
metadata:
name: kibana
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: kibana.k8s.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: kibana-svc
port:
number: 5601
EOF
电脑端设置host解析
等待一段时间等待机器起来
再起一个nginx来产生日志
并且把nginx日志改成json格式
[root@master ~/k8s_yml/ELK/nginx]# cat nginx-all.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format json '{ "time_local": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"http_user_agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"upstream_time": "$upstream_response_time",'
'"request_time": "$request_time"'
' }';
access_log /var/log/nginx/access.log json;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-dp
labels:
app: nginx-dp
spec:
replicas: 2
selector:
matchLabels:
app: nginx-dp
template:
metadata:
name: nginx-dp
labels:
app: nginx-dp
spec:
volumes:
- name: hostpath-volume
hostPath:
path: /data/logs
type: DirectoryOrCreate
- name: nginx-config
configMap:
name: nginx-config
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: nginx
image: nginx:1.14.0
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /var/log/nginx/
name: hostpath-volume
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
labels:
app: nginx-svc
spec:
selector:
app: nginx-dp
ports:
- name: nginx
port: 80
targetPort: 80
type: ClusterIP
这里面包括configmap,service,deployment
curl nginx地址
curl 10.2.2.70
创建filebeat
创建 filebeat-cm.yml文件
[root@master ~/k8s_yml/ELK/filebeat]# cat filebeat-cm.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
data:
filebeat.yml: |
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/logs/access.log
#json.keys_under_root: true
#json.overwrite_keys: true
tags: ["nginx"]
output.elasticsearch:
hosts: ["es-svc:9200"]
index: "nginx-access-%{[agent.version]}-%{+yyyy.MM}"
setup.ilm.enabled: false
setup.template.enabled: false
创建 DaemonSet资源,即每一个节点都要安装一个filebeat收集日志,master节点除外
把ConfigMap也写道里面一起
创建filebeat-ds-all.yaml
[root@master ~/k8s_yml/ELK/filebeat]# cat filebeat-ds-all.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
data:
filebeat.yml: |
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/logs/access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["nginx"]
output.elasticsearch:
hosts: ["es-svc:9200"]
index: "nginx-access-%{[agent.version]}-%{+yyyy.MM}"
setup.ilm.enabled: false
setup.template.enabled: false
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: filebeat-ds
labels:
app: filebeat-ds
spec:
selector:
matchLabels:
app: filebeat
template:
metadata:
name: filebeat
labels:
app: filebeat
spec:
volumes:
- name: hostpath-volume
hostPath:
path: /data/logs
type: DirectoryOrCreate
- name: filebeat-config
configMap:
name: filebeat-config
items:
- key: filebeat.yml
path: filebeat.yml
containers:
- name: filebeat
image: elastic/filebeat:7.17.0
imagePullPolicy: IfNotPresent
volumeMounts:
- name: hostpath-volume
mountPath: /data/logs
- name: filebeat-config
mountPath: /usr/share/filebeat/filebeat.yml
subPath: filebeat.yml
结果就是这样
如果是tomcat收集日志的话
先创建mysql目录
创建mysql-dp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-dp
labels:
app: mysql-dp
spec:
replicas: 1
selector:
matchLabels:
app: mysql-dp
template:
metadata:
namespace: tomcat
name: mysql-dp
labels:
app: mysql-dp
spec:
volumes:
- name: data
hostPath:
path: /data/mysql
imagePullSecrets:
- name: harbor-secret
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: [/bin/sh, -c, 'mysql -uroot -p123456 -e "show databases;"']
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
exec:
command: [/bin/sh, -c, 'mysql -uroot -p123456 -e "show databases;"']
initialDelaySeconds: 10
periodSeconds: 10
ports:
- name: http
containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: '123456'
volumeMounts:
- name: data
mountPath: /var/lib/mysql
再创建mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
labels:
app: mysql-svc
spec:
selector:
app: mysql-dp
ports:
- name: mysql-dp
port: 3306
targetPort: 3306
创建app目录
创建comfigmap
cat >create_cm.sh<<'EOF'
#!/bin/bash
kubectl create configmap tomcat-cm --from-file=server.xml=./server.xml
EOF
添加server.xml文件
cat >server.xml <<'EOF'
<?xml version='1.0' encoding='utf-8'?>
<!--
31Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="{"clientip":"%h","ClientUser":"%l","authenticated":"%u","AccessTime":"%t","method":"%r","status":"%s","SendBytes":"%b","Query?string":"%q","partner":"%{Referer}i","AgentVersion":"%{User-Agent}i"}"/>
</Host>
</Engine>
</Service>
</Server>
EOF
创建tomcat-svc.yaml
cat >tomcat-svc.yaml<<'EOF'
apiVersion: v1
kind: Service
metadata:
name: tomcat-svc
labels:
app: tomcat-svc
spec:
selector:
app: tomcat-dp
ports:
- name: tomcat
port: 8080
targetPort: 8080
EOF
创建tomcat-dp.yaml
cat > tomcat-dp.yaml<<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-dp
labels:
app: tomcat-dp
spec:
replicas: 2
selector:
matchLabels:
app: tomcat-dp
template:
metadata:
namespace: tomcat
name: tomcat-dp
labels:
app: tomcat-dp
spec:
volumes:
- name: hostpath-volume
hostPath:
path: /data/logs/tomcat/
type: DirectoryOrCreate
- name: tomcat-cm
configMap:
name: tomcat-cm
items:
- key: server.xml
path: server.xml
initContainers:
- name: init
image: busybox:latest
args: [/bin/sh, -c, 'until nc -zv mysql-svc 3306;do echo nonono;sleep 1;done']
containers:
- name: tomcat
image: kubeguide/tomcat-app:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
livenessProbe:
httpGet:
path: /demo/index.jsp
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /demo/index.jsp
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
env:
- name: MYSQL_SERVICE_HOST
value: mysql-svc
volumeMounts:
- name: tomcat-cm
mountPath: /usr/local/tomcat/conf/server.xml
subPath: server.xml
- name: hostpath-volume
mountPath: /usr/local/tomcat/logs
EOF
创建ingress文件,tomcat-ingress.yaml
cat >tomcat-ingress.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tomcat-ingress
spec:
rules:
- host: tomcat.k8s.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: tomcat-svc
port:
number: 8080
EOF
那么filebeat就要修改了,添加tomcat标记
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
data:
filebeat.yml: |
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/logs/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["nginx"]
- type: log
enabled: true
paths:
- /data/logs/tomcat/localhost_access_log.*.txt
json.keys_under_root: true
json.overwrite_keys: true
tags: ["tomcat"]
output.elasticsearch:
hosts: ["es-svc:9200"]
indices:
- index: "nginx-access-%{[agent.version]}-%{+yyyy.MM}"
when.contains:
tags: "nginx"
- index: "tomcat-access-%{[agent.version]}-%{+yyyy.MM}"
when.contains:
tags: "tomcat"
setup.ilm.enabled: false
setup.template.enabled: false
helm
就k8s的包管理工具
比如centos有自己的包管理工具 yum
docker有docker pull镜像
乌班图有apt
k8s都是一个一个资源都需要自己写deployment,pv,pvc等等
但是k8s有一个helm,别人写好了一个模板,里面都有,只需要该一个变量就可以用
Helm基础使⽤
安装
wget https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz
tar zxf helm-v3.6.3-linux-amd64.tar.gz -C /opt/
cp /opt/linux-amd64/helm /usr/local/bin/
helm version
仓库指南
https://artifacthub.io/packages/search?kind=0
添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stable https://charts.helm.sh/stable
helm官网
查看仓库列表
helm repo list
更新helm
helm repo update
查找一个叫nginx的软件包
helm search repo nginx
查看具体软件信息,比如bitnami/nginx ,chart 图表的意思
helm show chart bitnami/nginx
helm show all bitnami/nginx
all更加详细信息
查看可以配置的参数
helm show values bitnami/nginx
安装软件
helm install nginx bitnami/nginx
helm install bitnami/nginx --generate-name
查看已经部署的版本
helm list
查看已经安装的软件信息
helm status mysql-1628598079
卸载软件
helm uninstall nginx-xxxx
命令补全
source <(helm completion bash)
echo "source <(helm completion bash)" >> ~/.bash_profile
3.实战:⾃定义nginx包变量
查看官⽅变量说明:
https://github.com/bitnami/charts/tree/master/bitnami/nginx
⾃定义变量:
cat > nginx_values.yaml<<'EOF'
replicaCount: 2
podLabels:
app: mynginx
service:
type: ClusterIP
port: 80
ingress:
enabled: true
pathType: ImplementationSpecific
hostname: nginx.k8s.com
path: /
EOF
10.测试运行效果
helm install --debug --dry-run -f nginx-values.yml nginx bitnami/nginx
正式安装
helm install -f nginx_values.yaml -n nginx-helm nginx bitnami/nginx
运行之前要创建一个命名空间
kubectl create namespace nginx-helm
查看资源创建情况
kubectl -n nginx-helm get all
电脑配置host解析
访问测试
再次执行会报错,可以使用更新命令