单机部署一个mysql+tomcat应用栈
前期准备工作
使用centos7虚拟机
- 关闭centos防火墙
systemctl stop firewalld systemctl disable firewalld
- 安装etcd及kubernetes软件
yum update -y yum install etcd kubernetes -y
- 安装好的各软件版本如下
kubectl: v1.5.2
docker: 1.13.1
etcd: 3.2.15
- 修复配置文件
- docker配置文件/etc/sysconfig/docker
修改为OPTIONS=‘--selinux-enabled=false‘
-
- kubernetes apiserver配置文件 /etc/kubernetes/apiserver
KUBE_ADMISSION_CONTROL参数中删除ServiceAccount
- 使用daocloud加速器
注册daocloud用户后,运行daocloud加速器脚本
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://41379ba5.m.daocloud.io
# 由于网络原因,最好使用加速器。
# 如果使用daocloud后,出现镜像下载问题,可以考虑替换为阿里云加速器
# 实际上就是编辑了/etc/docker/daemon.json文件
# 如果docker镜像下载出现问题,优先考虑网络问题。
- 启动服务
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy
- 下载镜像
# mysql镜像
docker pull daocloud.io/library/mysql:latest
# tomcat镜像
docker pull kubeguide/tomcat-app:v2
[[email protected] docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daocloud.io/library/mysql latest 80bbf861367a 3 days ago 445 MB
docker.io/kubeguide/tomcat-app v2 00beaa1d956d 21 months ago 358 MB
启用mysql容器服务
定义rc模板,命名为mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
#定义RC标签选择
selector:
app: mysql
#定义Pod模板
template:
metadata:
labels:
app: mysql
spec:
#Pod内容器定义
containers:
- name: mysql
# image需要指定docker images输出中的那个mysql镜像
image: daocloud.io/library/mysql:latest
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
注意image选择,是与书中不一致的,因为我们下载的mysql镜像是daocloud仓库中的镜像
创建好文件后,发布到kubernetes集群中
[[email protected] kube-test]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql" created
[[email protected] kube-test]# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 1 1 0 10s
[[email protected] kube-test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-nrcvt 0/1 ContainerCreating 0 27s
这个ContainerCreating状态是异常状态,会一直持续,不会进入到running状态
查看pods状态时,
kubectl describe pods mysql-nrcvt
......
......
1m 5s 5 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""
发现是无法下载这个镜像,于是我手动pull这个镜像,发现如下报错:
[[email protected] kube-test]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory
搜索这个报错,发现可以通过yum install rhsm -y解决
运行该命令后,删除掉之前部署的rc,
[[email protected] kube-test]# kubectl delete rc mysql
replicationcontroller "mysql" deleted
[[email protected] kube-test]# kubectl get pods
No resources found.
重新部署
[[email protected] kube-test]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql" created
[[email protected] kube-test]# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 1 1 1 7s
[[email protected] kube-test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-nbwvp 1/1 Running 0 13s
mysql正常运行了。
查看正在运行的docker,发现有两个
[[email protected] kube-test]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f58905ddee64 daocloud.io/library/mysql:latest "docker-entrypoint..." About a minute ago Up About a minute k8s_mysql.9ef925be_mysql-nbwvp_default_30da097b-4ee8-11e8-a311-000c29f71e04_7ac92ba7
99382a3dcbf0 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" About a minute ago Up About a minute k8s_POD.1d520ba5_mysql-nbwvp_default_30da097b-4ee8-11e8-a311-000c29f71e04_aad8e14a
原文地址:http://blog.51cto.com/duf0913/2112491
时间: 2024-10-10 15:48:41