redis,docker和kubernetes留言簿案例实战
kubernetes实战-基于redis和docker的留言簿案例
版权声明:本文为博主原创文章,未经博主允许不得转载。
[root@centos1 example]# kubectl create -f redis-master-controller.json
replicationcontrollers/redis-master
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
redis-master master redis name=redis-master 1
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 55 seconds
master redis Running 55 seconds
[root@centos2 yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91689ce56668 redis:latest "/entrypoint.sh redi 3 minutes ago Up 3 minutes k8s_master.52732b08_redis-master-svar7_default_5b6d5485-1894-11e5-b3ad-000c293c8c19_97e79b7b
38c3180813c3 gcr.io/google_containers/pause:0.8.0 "/pause" 3 minutes ago Up 3 minutes k8s_POD.49eee8c2_redis-master-svar7_default_5b6d5485-1894-11e5-b3ad-000c293c8c19_298e038f
[root@centos1 example]# kubectl create -f redis-master-service.json
services/redis-master
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
[root@centos1 example]# kubectl create -f redis-slave-controller.json
replicationcontrollers/redis-slave
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
redis-master master redis name=redis-master 1
redis-slave slave kubernetes/redis-slave:v2 name=redis-slave 2
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 41 minutes
master redis Running 41 minutes
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 29 seconds
slave kubernetes/redis-slave:v2 Running 28 seconds
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 29 seconds
slave kubernetes/redis-slave:v2 Running 28 seconds
[root@centos1 example]# kubectl create -f redis-slave-service.json
services/redis-slave
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
[root@centos1 example]# kubectl create -f frontend-controller.json
replicationcontrollers/frontend
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
frontend php-redis kubernetes/example-guestbook-php-redis:v2 name=frontend 3
redis-master master redis name=redis-master 1
redis-slave slave kubernetes/redis-slave:v2 name=redis-slave 2
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
frontend-fr5z1 172.17.0.13 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
frontend-gjx3t 172.17.0.14 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
frontend-v608r 172.17.0.12 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 53 minutes
master redis Running 53 minutes
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 12 minutes
slave kubernetes/redis-slave:v2 Running 12 minutes
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 12 minutes
slave kubernetes/redis-slave:v2 Running 12 minutes
[root@centos1 example]# kubectl create -f frontend-service.json
services/frontend
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
NodePort
s 和LoadBalancer
s,https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#external-services[root@centos1 example]# kubectl get pods,services
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
frontend-fr5z1 172.17.0.13 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
frontend-gjx3t 172.17.0.14 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
frontend-v608r 172.17.0.12 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running About an hour
master redis Running About an hour
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 32 minutes
slave kubernetes/redis-slave:v2 Running 32 minutes
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 32 minutes
slave kubernetes/redis-slave:v2 Running 32 minutes
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
kubernetes component=apiserver,provider=kubernetes <none> 10.254.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 10.254.0.1 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
kubernetes component=apiserver,provider=kubernetes <none> 10.254.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 10.254.0.1 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
-A KUBE-PORTALS-HOST -d 10.254.154.90/32 -p tcp -m comment --comment "default/redis-master:" -m tcp --dport 6379 -j DNAT --to-destination 192.168.1.112:49038
[root@centos2 yum.repos.d]# redis-cli -p 49038
127.0.0.1:49038> set a b
OK
127.0.0.1:49038> get a
"b"
curl "localhost:8000/index.php?cmd=set&key=messages&value=jay_sais_hi"
curl "localhost:8000/index.php?cmd=get&key=messages"
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-master",
"labels":{
"name":"redis-master"
}
},
"spec":{
"replicas":1,
"selector":{
"name":"redis-master"
},
"template":{
"metadata":{
"labels":{
"name":"redis-master"
}
},
"spec":{
"containers":[
{
"name":"master",
"image":"redis",
"ports":[
{
"containerPort":6379
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-master",
"labels":{
"name":"redis-master"
}
},
"spec":{
"ports": [
{
"port":6379,
"targetPort":6379
}
],
"selector":{
"name":"redis-master"
}
}
}
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-slave",
"labels":{
"name":"redis-slave"
}
},
"spec":{
"replicas":2,
"selector":{
"name":"redis-slave"
},
"template":{
"metadata":{
"labels":{
"name":"redis-slave"
}
},
"spec":{
"containers":[
{
"name":"slave",
"image":"kubernetes/redis-slave:v2",
"ports":[
{
"containerPort":6379
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-slave",
"labels":{
"name":"redis-slave"
}
},
"spec":{
"ports": [
{
"port":6379
}
],
"selector":{
"name":"redis-slave"
}
}
}
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"replicas":3,
"selector":{
"name":"frontend"
},
"template":{
"metadata":{
"labels":{
"name":"frontend"
}
},
"spec":{
"containers":[
{
"name":"php-redis",
"image":"kubernetes/example-guestbook-php-redis:v2",
"ports":[
{
"containerPort":80
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"ports": [
{
"port":80
}
],
"selector":{
"name":"frontend"
}
}
}
redis,docker和kubernetes留言簿案例实战的更多相关文章
- 基于redis和docker的guestbook留言簿案例
在正式介绍之前,大家有必要先理解Kubernetes几个核心概念及其承担的功能.以下为Kubernetes的架构设计图: 1. Pods在Kubernetes系统中,调度的最小颗粒不是单纯的容器,而是 ...
- Spark Streaming updateStateByKey案例实战和内幕源码解密
本节课程主要分二个部分: 一.Spark Streaming updateStateByKey案例实战二.Spark Streaming updateStateByKey源码解密 第一部分: upda ...
- Spark Streaming 进阶与案例实战
Spark Streaming 进阶与案例实战 1.带状态的算子: UpdateStateByKey 2.实战:计算到目前位置累积出现的单词个数写入到MySql中 1.create table CRE ...
- 在Docker和Kubernetes上运行MongoDB微服务
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟.容器是完全使用沙箱机制,相互之间不会有任何接 ...
- 基于HDFS的SparkStreaming案例实战和内幕源码解密
一:Spark集群开发环境准备 启动HDFS,如下图所示: 通过web端查看节点正常启动,如下图所示: 2.启动Spark集群,如下图所示: 通过web端查看集群启动正常,如下图所示: 3.启动sta ...
- Kubernetes 应用部署实战
Kubernetes 应用部署实战 2018-08-08 19:44:56 wuxiangping2017 阅读数 3084 收藏 更多 分类专栏: linux运维与架构师 简介 伙计们,请搬好 ...
- (升级版)Spark从入门到精通(Scala编程、案例实战、高级特性、Spark内核源码剖析、Hadoop高端)
本课程主要讲解目前大数据领域最热门.最火爆.最有前景的技术——Spark.在本课程中,会从浅入深,基于大量案例实战,深度剖析和讲解Spark,并且会包含完全从企业真实复杂业务需求中抽取出的案例实战.课 ...
- 《图解Spark:核心技术与案例实战》作者经验谈
1,看您有维护博客,还利用业余时间著书,在技术输出.自我提升以及本职工作的时间利用上您有没有什么心得和大家分享?(也可以包含一些您写书的小故事.)回答:在工作之余能够写博客.著书主要对技术的坚持和热爱 ...
- 图解CSS3核心技术与案例实战(1)
前言: 我买了一本<图解CSS3核心技术与案例实战>大漠写的,为了提高自己的自觉性呢,抓紧看书,把读书笔记放在这上面,跟大家一起分享,也为督促自己完成读书计划. 文末有微信公众号,感谢你的 ...
随机推荐
- POJ 2823 Sliding Window 线段树
http://poj.org/problem?id=2823 出太阳啦~^ ^被子拿去晒了~晚上还要数学建模,刚才躺在床上休息一下就睡着了,哼,还好我强大,没有感冒. 话说今年校运会怎么没下雨!!!说 ...
- UVALive - 4960 Sensor network(生成树+LCA)
题目大意:给出N个点.M条边.问这N个点形成的生成树的最大权值边-最小权值边的最小值 解题思路:先排序,然后按生成树的kruscal算法进行加边,再维护一个最小权值边 加边的时候要考虑一下加下去的边是 ...
- Injector Job深入分析 分类: H3_NUTCH 2015-03-10 15:44 334人阅读 评论(0) 收藏
Injector Job的主要功能是根据crawlId在hbase中创建一个表,将将文本中的seed注入表中. (一)命令执行 1.运行命令 [jediael@master local]$ bin/n ...
- php压缩
php压缩的一个demo,随便测试了一下,可以用 <?php class PHPZip { private $ctrl_dir = array(); private $datasec = arr ...
- 2020发布 .NET 5 下一代全平台 .Net 框架
[翻译] 正式宣布 .NET 5 2019-05-07 01:18 by Rwing, 16515 阅读, 79 评论, 收藏, 编辑 原文: Introducing .NET 5 今天,我们宣布 . ...
- [Ramda] allPass, propEq
const needs = ['wifi', 'shower', 'laundry']; const homes = [{ name: 'Home 1', wifi: 'y', shower: 'y' ...
- php计算两个坐标直线距离
function rad($d) { return $d * 3.1415926535898 / 180.0; } function GetDistance($lat1, $lng1, $lat2, ...
- USB 3.0规范中译本 第3章 USB 3.0体系结构概览
本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 本章呈现USB 3.0体系结构和关键概念的概览.USB 3.0与前面版本的USB类似,因为它是线缆总线,支持 ...
- 【AJAX】AJAX实现搜索信息自己主动推荐并补全
好久没有继续看AJAX的视频教程了,今天就将最后一个教程案例做完.我们在搜索引擎中输入文字时文本框下会提示对应的信息,这个案例就是实现这样的基本功能,代码比較粗糙还须要进一步完好,当中有些地方也须要向 ...
- 走进windows编程的世界-----窗体的注冊及创建
1 窗体注冊和创建 1.1WIN32 窗体程序创建步骤 1.WinMain入口函数的定义 2.WindowProc函数的定义 3.注冊窗体类 RegisterClass.RegisterClass ...