1.2Kubernetes快速入門(mén)
環(huán)境準(zhǔn)備:
關(guān)閉CentOS防火墻
?????systemctl disable firewalld
?????systemctl stop firewalld
安裝etcd和kubernetes軟件
? ? yum install -y etcd kubernetes
啟動(dòng)服務(wù)
? ? systemctl start etcd? ?(用于配置共享和服務(wù)發(fā)現(xiàn)的鍵值存儲(chǔ)系統(tǒng))
? ? systemctl start docker (創(chuàng)建容器的)
????????????????如果docker啟動(dòng)h失斚律摇(參考vi /etc/sysconfig/selinux? ?將selinux后面的改為disable,重啟服務(wù)器笛坦,再重啟docker即可)
? ? systemctl start kube-apiserver? (API Server是整個(gè)系統(tǒng)的對(duì)外接口,供客戶(hù)端和其它組件調(diào)用,相當(dāng)于“營(yíng)業(yè)廳”)
? ? systemctl start kube-controller-manager? (Controller manager負(fù)責(zé)管理控制器榔组,相當(dāng)于“大總管”左腔。)
????systemctl start kube-scheduler? ?(Scheduler負(fù)責(zé)對(duì)集群內(nèi)部的資源進(jìn)行調(diào)度餐屎,相當(dāng)于“調(diào)度室”福也。)
????systemctl start kubelet? ?(Kubelet工育,主要負(fù)責(zé)監(jiān)視指派到它所在Node上的Pod逃默,包括創(chuàng)建鹃愤、修改、監(jiān)控完域、刪除等软吐。)
? ? systemctl start kube-proxy (Kube-proxy,主要負(fù)責(zé)為Pod對(duì)象提供代理吟税。)
配置
tomcat配置:/usr/local/k8s/
mytomcat-rc.yaml
????kubectl? create -f mytomcat-rc.yaml
mytomcat-svc.yaml
????kubectl create -f mytomcat-svc.yaml
????kubectl get svc? :查看服務(wù)
問(wèn)題解決
docker pull 失敗
? ??1. yum install rhsm -y?
? ??2. docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
????如果以上 兩步可以解決問(wèn)題凹耙,則不需要執(zhí)行以下步驟姿现。
????3. docker search pod-infrastructure
????4. docker pull docker.io/tianyebj/pod-infrastructure
????5. docker tag tianyebj/pod-infrastructure 192.168.0.19:5000/pod-infrastructure
????6. docker push 192.168.0.19:5000/pod-infrastructure
????7. vi /etc/kubernetes/kubelet
????修改KUBELET_POD_INFRA_CONTAINER="-pod-infra-container-image=192.168.0.19:5000/pod-infrastructure:latest"
????8. 重啟服務(wù)
????????systemctl restart kube-apiserver?
????????systemctl restart kube-controller-manager?
????????systemctl restart kube-scheduler?
????????systemctl restart kubelet?
????????systemctl restart kube-proxy
????方案二:
????1. docker pull kubernetes/pause
? ? 2. docker tag docker.io/kubernetes/pause:latest ????????192.168.0.19:5000/google_containers/pause-amd64.3.0
????3. docker push 192.168.0.19:5000/google_containers/pause-amd64.3.0
????4. vi /etc/kubernetes/kubelet配置為:
????????KUBELET_ARGS="-? pod_infra_container_image=192.168.0.19:5000/google_containers/pause-amd64.3.0"
????5. 重啟kubelet服務(wù):systemctl restart kubelet
外網(wǎng)不能訪問(wèn)
? ? 在搭建好的k8s集群內(nèi)創(chuàng)建的容器,只能在其所在的節(jié)點(diǎn)上curl可訪問(wèn)肖抱,但是在其他任何主機(jī)上無(wú)法訪問(wèn)容器占用端口????
? ? 解決方案:
? ????? 1. vim /etc/sysctl.conf
? ????? 2. net.ipv4.ip_forward=1
kubectl get pods時(shí)No resources found問(wèn)題
? ? ????1. vim /etc/kubernetes/apiserver
? ? ? ? 2. 找到KUBE_ADMISSION_CONTROL="-admission_control=NamespaceLifecycle,NameSpaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota",去掉ServiceAccount,保存退出备典。
? ? ? ? 3. systemctl restart kube-apiserver
補(bǔ)充:
kubectl replace -f mytomcat-rc.yaml
kubectl delete svc --all
kubectl create -f mytomcat-svc.yaml