k8s部署nginx集群
环境:
两台虚拟机,
10.10.20.203 部署docker、etcd、flannel、kube-apiserver、kube-controller-manager、kube-scheduler
10.10.20.206 部署docker、flannel、kubelet、kube-proxy
1、创建nginx-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-controller
spec:
replicas:
selector:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort:
2、创建nginx-service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service-nodeport
spec:
ports:
- port:
targetPort:
protocol: TCP
type: NodePort
selector:
name: nginx
3、创建pod
kubectl create -f nginx-rc.yaml
4、创建service
kubectl create -f nginx-service-nodeport.yaml
5、查看pod
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-controller-v40nj / Running 1h
nginx-controller-zxdzh / Running 1h
[root@k8s-master ~]# kubectl describe pod nginx-controller-v40nj
Name: nginx-controller-v40nj
Namespace: default
Node: k8s-slave1-/60.19.29.21
Start Time: Thu, Aug :: -
Labels: name=nginx
Status: Running
IP: 10.0.83.3
Controllers: ReplicationController/nginx-controller
Containers:
nginx:
Container ID: docker://269adc9b693aba0356ba18e4253c2b498fc7b7a8ce0af83857fcfd6b70e6ef03
Image: nginx
Image ID: docker://sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d
Port: /TCP
State: Running
Started: Thu, Aug :: -
Last State: Terminated
Reason: Completed
Exit Code:
Started: Thu, Aug :: -
Finished: Thu, Aug :: -
Ready: True
Restart Count:
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
No volumes.
QoS Tier: BestEffort
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
5m 5m {kubelet k8s-slave1-} spec.containers{nginx} Normal Pulling pulling image "nginx"
5m 5m {kubelet k8s-slave1-} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
5m 5m {kubelet k8s-slave1-} spec.containers{nginx} Normal Pulled Successfully pulled image "nginx"
5m 5m {kubelet k8s-slave1-} spec.containers{nginx} Normal Created Created container with docker id 269adc9b693a
5m 5m {kubelet k8s-slave1-} spec.containers{nginx} Normal Started Started container with docker id 269adc9b693a
6、查看service
[root@k8s-master ~]# kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> /TCP 16h
nginx-service-nodeport 10.254.29.72 <nodes> /TCP 49m
[root@k8s-master ~]# kubectl describe service nginx-service-nodeport
Name: nginx-service-nodeport
Namespace: default
Labels: <none>
Selector: name=nginx
Type: NodePort
IP: 10.254.29.72
Port: <unset> /TCP
NodePort: <unset> /TCP
Endpoints: 10.0.83.2:,10.0.83.3:
Session Affinity: None
No events.
7、测试service是否好用
因为service使用的是NodePort方式,所以在任何一个节点访问31152这个端口都可以访问nginx
$ curl 10.10.20.203:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
$ curl 10.10.20.206:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
k8s部署nginx集群的更多相关文章
- 日志分析系统 - k8s部署ElasticSearch集群
K8s部署ElasticSearch集群 1.前提准备工作 1.1 创建elastic的命名空间 namespace编排文件如下: elastic.namespace.yaml --- apiVers ...
- 庐山真面目之十微服务架构 Net Core 基于 Docker 容器部署 Nginx 集群
庐山真面目之十微服务架构 Net Core 基于 Docker 容器部署 Nginx 集群 一.简介 前面的两篇文章,我们已经介绍了Net Core项目基于Docker容器部署在Linux服 ...
- k8s部署etcd集群
1.k8s部署高可用etcd集群时遇到了一些麻烦,这个是自己其中一个etcd的配置文件 例如: [Unit] Description=Etcd Server After=network.target ...
- Kubernetes(k8s)部署redis-cluster集群
Redis Cluster 提供了一种运行 Redis 安装的方法,其中数据 在多个 Redis 节点之间自动分片. Redis Cluster 还在分区期间提供了一定程度的可用性,这实际上是在某些节 ...
- k8s部署kafka集群
一.概述 在k8s里面部署kafka.zookeeper这种有状态的服务,不能使用deployment和RC,k8s提供了一种专门用来部署这种有状态的服务的API--statefulset,有状态简单 ...
- 阿里云k8s部署zookeeper集群
1. 阿里云k8s创建有状态应用 StatefulSet , 选择使用模板创建 可以创建自定义模板 apiVersion: apps/v1 kind: StatefulSet metadata: c ...
- Kubeadm部署K8S(kubernetes)集群(测试、学习环境)-单主双从
1. kubernetes介绍 1.1 kubernetes简介 kubernetes的本质是一组服务器集群,它可以在集群的每个节点上运行特定的程序,来对节点中的容器进行管理.目的是实现资源管理的自动 ...
- NetCore在Centos7上部署和Nginx集群部署访问
NetCore在Linux上部署 工具:WMWare虚拟机,Wmware12,CentOS7ISO镜像,VS2017 1.安装虚拟机,过程略,网上一搜一大把 2.用VS2017建一个NetCore的W ...
- .Net Core2.1 秒杀项目一步步实现CI/CD(Centos7.2)系列一:k8s高可用集群搭建总结以及部署API到k8s
前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署的,这个集群差不多搞了一周时间,关于k8s的知识点,我也是刚入门,这方面的知识建议参考博客园 ...
随机推荐
- AtCoder - 4130 K-th Substring
Problem Statement You are given a string s. Among the different substrings of s, print the K-th lexi ...
- 【hdu3652】数位dp(浅尝ACM-A)
向大佬学习 第一次写博客有点紧张,也算是小萌新的突破吧 这次主要是总结一下校内的ACM比赛的各种题,主要是新思路以及学到的新知识 先放一张 下面开始说正事 题面 A wqb-number, or B- ...
- 【bzoj2839】【集合计数】容斥原理+线性求阶乘逆元小技巧
(上不了p站我要死了,侵权度娘背锅) Description 一个有N个元素的集合有2^N个不同子集(包含空集),现在要在这2^N个集合中取出若干集合(至少一个),使得 它们的交集的元素个数为K,求取 ...
- 关于UIWebView设置高度自适应的问题
- (void)viewDidLoad { [super viewDidLoad]; _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMa ...
- 远程访问CENTOS的MYSQL数据库设置
远程访问CENTOS的MYSQL数据库设置 mysql -u root grant all privileges on *.* to root@'%'identified by 'root'; 后面的 ...
- Facebook KeyHash生成方法
1. 去https://code.google.com/p/openssl-for-windows/downloads/list下载OpenSSL工具 2. 在C盘根目录下新建一个openssl的文 ...
- hdu1048(c++)
用string串来处理这个题很方便 #include<iostream>#include<string>using namespace std;string cipher(st ...
- WIN7无法卸载掉中文繁体注音输入法
WIN7无法卸载掉中文繁体注音输入法 不知何时系统里被自动安装了个中文繁体的注音输入法,每次启动都会替换默认的简体搜狗拼音,而且最要命的是在输入法选择栏里面没有出现这个繁体的输入法,而任务栏里却总是有 ...
- elasticsearch 基础性操作
1 基础概念 Elasticsearch是一个近实时的系统,从你写入数据到数据可以被检索到,一般会有1秒钟的延时.Elasticsearch是基于Lucene的,Lucene的读写是两个分开的句柄,往 ...
- Android使用TextView,设置onClick属性无效解决的方法
Android在布局文件里为View提供了onClick属性.用法例如以下: <TextView android:id="@+id/user" android:layout_ ...