我们平时用docker部署几个容器,可以花很少的时间去管理和维护,但是假如在生产环境中有几百个容器,这该如何管理,并且还能保证我们的服务实现高可靠,高并发,于是k8s就出现了。
他能为我们提供一个可弹性运行分布式系统的框架,主要可以为我们实现以下功能
角色 主机名 IP地址
Master master 192.168.175.3
Node node1 192.168.175.250
# 关闭防火墙 systemctl disable firewalld systemctl stop firewalld # 关闭selinux # 临时禁用selinux setenforce 0 # 永久关闭 修改/etc/sysconfig/selinux文件设置 sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config # 禁用交换分区 swapoff -a # 永久禁用,打开/etc/fstab注释掉swap那一行。 sed -i 's/.*swap.*/#&/' /etc/fstab # 修改内核参数 cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
命令:[root@master ~]# yum install -y kubernetes etcd flannel ntp 命令:[root@node1 ~]# yum install -y kubernetes etcd flannel ntp
命令:[root@master ~]# vim /etc/etcd/etcd.conf #修改以下配置 ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://192.168.175.3:2379" ETCD_NAME="etcd" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.175.3:2379"
命令:[root@master ~]# systemctl start etcd 命令:[root@master ~]# systemctl status etcd 命令:[root@master ~]# systemctl enable etcd
命令:[root@master ~]# ss -antulp | grep 2379
命令:[root@master ~]# etcdctl member list 只有一台
命令:[root@master ~]# vim /etc/kubernetes/config #修改以下配置文件 KUBE_MASTER="--master=http://192.168.175.3:8080"
命令:[root@master ~]# vim /etc/kubernetes/apiserver KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.175.3:2379" KUBE_ADMISSION_CONTROL="--admission-control=AlwaysAdmit"
命令:[root@master ~]# vim /etc/kubernetes/scheduler KUBE_SCHEDULER_ARGS="0.0.0.0"
命令:[root@master ~]# etcdctl mkdir /k8s/network 命令:[root@master ~]# etcdctl set /k8s/network/config '{"Network": "10.255.0.0/16"}' 命令:[root@master ~]# etcdctl get /k8s/network/config
命令:[root@master ~]# vim /etc/sysconfig/flanneld FLANNEL_ETCD_ENDPOINTS="http://192.168.175.3:2379" FLANNEL_ETCD_PREFIX="/k8s/network" FLANNEL_OPTIONS="--iface=ens33" #设置自己的通信物理网卡
命令:[root@master ~]# systemctl restart kube-apiserver kube-controller-manager kube-scheduler flanneld 命令:[root@master ~]# systemctl status kube-apiserver kube-controller-manager kube-scheduler flanneld 命令:[root@master ~]# systemctl enable kube-apiserver kube-controller-manager kube-scheduler flanneld
命令:[root@node1 ~]# vim /etc/sysconfig/flanneld FLANNEL_ETCD_ENDPOINTS="http://192.168.175.3:2379" FLANNEL_ETCD_PREFIX="/k8s/network" FLANNEL_OPTIONS="--iface=ens33"
命令:[root@node1 ~]# vim /etc/kubernetes/config KUBE_MASTER="--master=http://192.168.175.3:8080"
命令:[root@node1 ~]# vim /etc/kubernetes/kubelet KUBELET_ADDRESS="--address=0.0.0.0" KUBELET_HOSTNAME="--hostname-override=node1" KUBELET_API_SERVER="--api-servers=http://192.168.175.3:8080" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
命令:[root@node1 ~]# systemctl restart flanneld kube-proxy kubelet docker 命令:[root@node1 ~]# systemctl enable flanneld kube-proxy kubelet docker 命令:[root@node1 ~]# systemctl status flanneld kube-proxy kubelet docker
***至此k8s集群已经搭建完毕
apiVersion: apps/v1beta1 kind: Deployment metadata: name: hello-k8s spec: replicas: 2 template: metadata: labels: app: hello-k8s spec: containers: - name: k8s image: liuqiangdocker/qiangk8s:v1.0 ports: - containerPort: 8888
apiVersion: v1 kind: Service metadata: name: hello-k8s spec: type: NodePort ports: - port: 8888 nodePort: 30001 selector: app: hello-k8s
kubectl create -f k8s_deployment.yml kubectl create -f k8s_service.yml ********** 特别特别注意:由于k8s版本更迭太快,1.5.2不支持apiVersion: apps/v1 service: Deployment,如果报 kind not match相关的很大可能是版本不对
我们可以用 kubectl get pod 来查看我们创建的容器,因为我在deployment里面,将replica设置为2
如果你发现你的pod处于ContainerCreating状态,可以用这个命令查看pod的细节 kubectl describe pod 你的pod名,主要看detail,我就出现这个问题
查了资料原来是这个目录是一个空目录,通过软链指过去的,这篇文章可以解决你的问题
转载 https://blog.csdn.net/weixin_37480442/article/details/81949217