1、Master节点:
etcd: 分布式键值对数据库,保存集群状态
api-server: 接受并响应用户的请求
controller: 控制器管理,控制容器的副本数,故障检测
scheduler: 资源调度器,选择启动容器的node节点
2、Node节点:
kubelet: 调用docker,管理容器生命周期
kube-proxy: 提供网络访问,负载均衡
1、安装docker(所有节点)
2、安装etcd(key=value数据库)
1) 安装配置
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://10.0.0.11:2379"
2) 启动服务
3) 端口检测及测试服务状态
2379 #客户端连接端口
2380 #etcd集群连接端口
3、安装k8s-master
1) 安装配置
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://10.0.0.11:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_MASTER="--master=http://10.0.0.11:8080"
2) 启动服务
3) 测试
4、安装k8s-node
1) 安装配置
KUBE_MASTER="--master=http://10.0.0.11:8080"
KUBELET_ADDRESS="--address=10.0.0.12"
KUBELET_HOSTNAME="--hostname-override=10.0.0.12"
KUBELET_API_SERVER="--api-servers=http://10.0.0.11:8080"
2) 启动服务
3) 检查服务(master节点执行)
5、安装flannel(跨主机通信)
1) 安装配置(所有节点)
FLANNEL_ETCD_ENDPOINTS="http://10.0.1.11:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
2) 配置网络(master节点)
3) 启动服务
4) 重启所有服务(所有节点)
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service
systemctl restart kubelet.service
systemctl restart kube-proxy.service
5) 检查服务
ifconfig flannel0
6、配置私有镜像仓库
1) 配置镜像加速和私有仓库地址(master节点)
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://registry.docker-cn.com --insecure-registry=10.0.0.11:5000'
2) 启动私有仓库(master节点)
3) 推送镜像测试(node节点)
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry=10.0.0.11:5000'
1、yaml的主要组成
apiVersion: v1 api版本
kind: pod 资源类型
metadata: 属性
spec: 详细
2、pod文件
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: web
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/oldguonginx:v1
ports:
- containerPort: 80
3、pod基本操作
创建
查询
删除
更新
其他
1、介绍
ReplicationController: 副本控制器,rc通过标签(metadata)选择器(selector)来管理pod
rc: 保证指定数量的pod始终存活,弹性伸缩,滚动升级
2、创建rc文件
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx #rc名
spec:
replicas: 3 #副本数
selector:
app: nginx #管理pod名
template:
metadata:
labels:
app: nginx #pod名
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/oldguo/nginx:1.13
ports:
3、rc的基本操作
1) 创建
2) 查看
3) 删除pod,rc会自动创建
4) 更新
5) 滚动的升级和回滚
1、介绍
拥有rc的功能,支持事件,状态查看,版本记录等
2、创建deployment文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/oldguo/nginx:1.13
ports:
- containerPort: 80
3、deployment的基本操作
1) 创建
2) 查看
3) 删除
4) 更新
5) 滚动的升级和回滚
1、介绍
service提供了一个固定虚拟VIP,通过IP访问pod,并且提供负载均衡
Node IP -----> Cluster IP -----> Pod IP
2、创建svc配置文件
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
selector:
app: nginx
3、svc的基本操作
1) 创建
2) 查看
3) 删除
4) 更新
1、创建pv文件
apiVersion: v1
kind: PersistentVolume
metadata:
name: test01-pv #pv的名
labels:
pv: test01 #标签名
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: "/data"
server: 10.0.0.11
readOnly: false
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-test02
labels:
pv: test02
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: "/mysql"
server: 10.0.0.11
readOnly: false
2、创建pvc文件
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc_nfs #pvc的名
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
selector:
matchLabels:
pv: test01 #绑定指定的pv(指定标签名)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc_mysql
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
selector:
matchLabels:
pv: test02
3、创建
1、安装配置NFS
1) master节点
/data 10.0.0.0/24(rw,async,no_root_squash,no_all_squash)
/code 10.0.0.0/24(rw,async,no_root_squash,no_all_squash)
2) node节点
2、定义pv
1) mysql的pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-data
labels:
type: pv-mysql
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: "/data"
server: 10.0.0.11
readOnly: false
2) wordpress的pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-code
labels:
type: pv-wp
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: "/code"
server: 10.0.0.11
readOnly: false
3、定义pvc
1) mysql的pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-mysql
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
selector:
matchLabels:
type: pv-mysql
2) wordpress的pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-wp
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
selector:
matchLabels:
type: pv-wp
4、创建 pv 和 pvc
5、创建mysql的rc
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: 10.0.0.11:5000/mysql:5.7
ports:
- containerPort: 3306
volumeMounts:
- name: nfs-vol
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
- name: MYSQL_DATABASE
value: "wordpress"
- name: MYSQL_USER
value: "wordpress"
- name: MYSQL_PASSWORD
value: "wordpress"
volumes:
- name: nfs-vol
persistentVolumeClaim:
claimName: pvc-mysql
6、创建mysql的svc
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
7、获取 MySQL 集群 IP
mysql 10.254.69.58
8、创建wordpress的rc
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 2
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: 10.0.0.11:5000/wordpress:latest
ports:
- containerPort: 80
volumeMounts:
- name: nfs-vol
mountPath: /var/www/html
env:
- name: WORDPRESS_DB_HOST
value: '10.254.69.58'
- name: WORDPRESS_DB_USER
value: 'wordpress'
- name: WORDPRESS_DB_PASSWORD
value: 'wordpress'
volumes:
- name: nfs-vol
persistentVolumeClaim:
claimName: pvc-wp
9、创建wordpress的svc
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 80
nodePort: 30008
selector:
app: myweb
10、测试
浏览器访问
http://10.0.0.11:30008/
手机扫一扫
移动阅读更方便
你可能感兴趣的文章