使用kubernetes部署Elasticsearch应用(单节点)
背景简介:kubernetes部署应用,特别的方便。用户只需要提交应用服务所需要的资源就可以了(通常是一个yaml配置文件),虽然没学过kubernetes,网上很多可以搭建k8s集群的博客(以后会学习)一、下载相关镜像yaml文件中用到的镜像,下载本地之后。通过docker命令查看(官方镜像需要使用VPN,学习这些开源项目必须克服网络问题,要不然门都很难进啊)深有体会[root@nod...
·
背景简介:
kubernetes部署应用,特别的方便。用户只需要提交应用服务所需要的资源就可以了(通常是一个yaml配置文件),虽然没学过kubernetes,网上很多可以搭建k8s集群的博客(以后会学习)
一、 下载相关镜像
yaml文件中用到的镜像,下载本地之后。通过docker命令查看(官方镜像需要使用VPN,学习这些开源项目必须克服网络问题,要不然门都很难进啊)深有体会
这个镜像是我在官网 下载之后传到了自己的阿里云镜像仓库中保存
[root@node001 elastic01]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 336262580e12 7 days ago 18.6 MB
registry.cn-beijing.aliyuncs.com/wangshuai/elasticsearch 6.4.0 1ac676545731 3 weeks ago 791 MB
二、 配置yaml文件
[root@node001 elastic01]# vim elasticsearch.yaml
apiVersion: v1 //版本号
kind: ReplicationController //k8s的RC资源
metadata:
name: elasticsearch
labels:
name: elasticsearch-logging //RC的全局唯一标识,名字
kubernetes.io/cluster-service: "true"
spec:
replicas: 1
selector:
name: elasticsearch-logging
template:
metadata:
name: es
labels:
name: elasticsearch-logging
kubernetes.io/cluster-service: "true"
spec:
containers:
- image: registry.cn-beijing.aliyuncs.com/wangshuai/elasticsearch:6.4.0 //docker 镜像
imagePullPolicy: Never
name: elasticsearch-logging
ports:
- name: es-port
containerPort: 9200
- name: es-tran-port
containerPort: 9300
volumeMounts:
- name: es-persistent-storage
mountPath: /data
volumes:
- name: es-persistent-storage
emptyDir: {}
三、 配置service
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-logging
labels:
name: elasticsearch-logging
kubernetes.io/cluster-service: "true"
spec:
type: NodePort
ports:
- port: 9200
targetPort: 9200
nodePort: 30009 // 指定一个远程访问端口
selector:
name: elasticsearch-logging
四、 部署测试
[root@node001 elastic01]# kubectl apply -f elasticsearch.yaml
replicationcontroller/elasticsearch created
[root@node001 elastic01]# kubectl apply -f elasticsearch-service.yaml
service/elasticsearch-logging created
pod的状态说明:ImagePullBackOff、ErrImageNeverPull
镜像错误,拉取出错
[root@node001 elastic01]# kubectl get pods
NAME READY STATUS RESTARTS AGE
curl-8fbc6f555-k47x9 0/1 ImagePullBackOff 0 1d
elasticsearch-9g2rs 0/1 ErrImageNeverPull 0 1m
nginx-5dbb4c75cd-9cbwl 1/1 Running 6 2d
nginx-5dbb4c75cd-rnpvj 1/1 Running 5 2d
重新部署:
[root@node001 elastic01]# kubectl delete -f elasticsearch.yaml
replicationcontroller "elasticsearch" deleted
[root@node001 elastic01]# kubectl delete -f elasticsearch-service.yaml
service "elasticsearch-logging" deleted
[root@node001 elastic01]# vim elasticsearch.yaml
[root@node001 elastic01]# kubectl apply -f elasticsearch.yaml
replicationcontroller/elasticsearch created
[root@node001 elastic01]# kubectl get pod
NAME READY STATUS RESTARTS AGE
curl-8fbc6f555-k47x9 0/1 ImagePullBackOff 0 1d
elasticsearch-pzd24 1/1 Running 0 17s
nginx-5dbb4c75cd-9cbwl 1/1 Running 6 2d
nginx-5dbb4c75cd-rnpvj 1/1 Running 5 2d
[root@node001 elastic01]# kubectl apply -f elasticsearch-service.yaml
service/elasticsearch-logging created
[root@node001 elastic01]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch-logging NodePort 10.100.126.10 <none> 9200:30009/TCP 11s
example-service ClusterIP 10.108.47.170 <none> 80/TCP 2d
example-service-nodeport NodePort 10.99.42.26 <none> 80:31991/TCP 2d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
测试访问:
[root@node001 elastic01]# curl "10.100.126.10:9200"//容器ip
{
"name" : "o27trev",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "Du89qx0DSwi3G8QBlPZ5lw",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[root@node001 elastic01]# curl http://192.168.223.5:30009//虚拟机ip
{
"name" : "o27trev",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "Du89qx0DSwi3G8QBlPZ5lw",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
更多推荐
已为社区贡献1条内容
所有评论(0)