环境准备(centos 7)

	1. 关闭CentOS防火墙
		systemctl disable firewalld
		systemctl stop  firewalld
	2. 安装 etcd 和kubenetes 软件
		yun install -y etcd kubernetes
	3. 启动服务
		systemctl start stcd
		systemctl start docker
		*** 如果 docker 启动失败 则修改 vim  /etc/sysconfig/selinux 
				把selinux 后面的改为 disable,    重启机器  在重启docker
		systemctl start kube-apiserver
		systemctl start kube-controller-manager
		systemctl start kube-scheduler
		systemctl start kubelet
		systemctl start kube-proxy

部署失败问题

	tomcat 配置
		mytomcat.rc.yaml
apiVersion: v1
kind: ReplicationController
metadata: 
  name: mytomcat
spec: 
  replicas: 2
  selector: 
    app: mytomcat
  template: 
    metadata: 
      labels: 
        app: mytomcat
    spec: 
      containers: 
        - 
          image: tomcat
          name: mytomcat
          ports: 
            - 
              containerPort: 8080
	mytomcat.svc.yaml
apiVersion: v1
kind: Service
metadata:
 name: mytomcat
spec:
 type: NodePort
 ports:
  - port: 8080
    nodePort: 30001
 selector:
  app: mytomcat
文件配置好之后
执行如下命令:
	kubectl create  -f mytomcat.rc.yaml
	kubectl create  -f mytomcat.svc.yaml

可能出现的问题:
	1. docker pull 失败
		1>  yum install rhsm -y
		2>  docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
		3>  docker search pod-infrastructure
		4>  docker pull docker.io/tianyebj/pod-infrastructure
		5> docker tag tianyebj/pod-infrastructure 192.168.126.143:5000/pod-infrastructure 
		6> docker push 192.168.126.143:5000/pod-infrastructure
		 docke push 可能失败,  查看register镜像是否存在 ,且正常运行,没有的话,拉取register 镜像,启动镜像
   		7> 修改:
   				vim  /etc/kubernetes/kubelet 
   				KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=192.168.1.103:5000/pod-infrastructure:lates" 			 
	2. 外网不能访问:
		 1> vim /etc/sysctl.conf
		 2>  sysctl.conf  添加
		 		net.ipv4.ip_forward=1
	
	首先保证:
		kubectl get pods 之后所有的容器 处于running 状态
		  NAME             READY     STATUS    RESTARTS   AGE
		  mytomcat-4r6fs   1/1       Running  0          5h
		  mytomcat-swsqk   1/1       Running   0          5h
   之后 访问  tomcat 服务器
		若无法访问:
			1. docker ps
			2.  docker exec -it  容器板Id  /bin/bash  # 进入容器
			3. 	pwd # 发现两个相似目录 webapp 和 webapp.dist
			4. rm -rf webapp 
			5 mv webapp.dist webapp
		重启服务:
			kubectl replace  -f  mytomcat.rc.yaml
			kubectl  delete svc --all
			kubectl get pods # 确认服务 running
			kubectl create -f mytomcat.svc.yaml
	最后重新进入浏览器 应该就没有什么问题了。。。
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐