kubernetes简单示例
1. 安装
yum install -y etcd kubernetes
2. 启动
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
3. 拉镜像
docker pull daocloud.io/library/mysql
docker pull daocloud.io/library/tomcat
4. 创建YAML文件
mysql-rc.yaml
1 apiVersion: v1 2 kind: ReplicationController 3 metadata: 4 name: mysql 5 spec: 6 replicas: 1 7 selector: 8 app: mysql 9 template: 10 metadata: 11 labels: 12 app: mysql 13 spec: 14 containers: 15 - name: mysql 16 image: daocloud.io/library/mysql 17 ports: 18 - containerPort: 3306 19 env: 20 - name: MYSQL_ROOT_PASSWORD 21 value: "123456"
mysql-svc.yaml
1 apiVersion: v1 2 kind: Service 3 metadata: 4 name: mysql 5 spec: 6 ports: 7 - port: 3306 8 selector: 9 app: mysql
myweb-rc.yaml
apiVersion: v1
1 apiVersion: v1 2 kind: ReplicationController 3 metadata: 4 name: myweb 5 spec: 6 replicas: 3 7 selector: 8 app: myweb 9 template: 10 metadata: 11 labels: 12 app: myweb 13 spec: 14 containers: 15 - name: myweb 16 image: daocloud.io/library/tomcat 17 ports: 18 - containerPort: 8080 19 env: 20 - name: MYSQL_SERVICE_HOST 21 value: "mysql" 22 - name: MYSQL_SERVICE_PORT 23 value: "3306"
myweb-svc.yaml
1 apiVersion: v1 2 kind: Service 3 metadata: 4 name: mysql 5 spec: 6 ports: 7 - port: 3306 8 selector: 9 app: mysql
5.创建replicationController以及Service
kubectl create -f /XX/mysql-rc.yaml kubectl create -f /XX/mysql-svc.yaml kubectl create -f /XX/myweb-rc.yaml kubectl create -f /XX/myweb-svc.yaml
6. 查看RC和Service运行状态
kubectl get pod mysql(应该是running状态)
kubectl get service mysql
kubectl get pod myweb(应该是running状态)
kubectl get service myweb
7. 查看kubectl的日志(如果有问题,则查看相应日志)
kubectl describe pod mysql(myweb)
kubectl describe service mysql(myweb)
8. 确认服务
http://ip:8080是否跳转到tomcat的欢迎页面,跳转则安装成功;
看到此处发现mysql其实并没有啥用,但是其实原始demo的tomcat是从hub.docker.com/u/kubeguide下面拉取,但是被墙了,于是就用daocloude的tomcat做替换。