centos 7 部署k8s集群
架构图:
前期准备
systemctl stop firewalld
systemctl disable firewalld
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd
yum update -y
安装etcd Kubernetes
yum -y install etcd kubernetes flannel
配置etcd
[root@kubernetes-master ~]# egrep -v "^#|^$" /etc/etcd/etcd.conf
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"
配置k8s api
[root@kubernetes-master ~]# egrep -v "^#|^$" /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://10.64.8.68:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
KUBE_API_ARGS=""
配置flannel网络
[root@kubernetes-master ~]# egrep -v "^#|^$" /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://10.64.8.68:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
启动etcd k8s服务
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
定义flannel network
[root@kubernetes-master ~]# etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
配置Kubernetes Minions (Nodes节点都执行一遍)
yum -y install flannel kubernetes
配置/etc/sysconfig/flanneld
[root@kubernetes-node2 ~]# egrep -v "^#|^$" /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://10.64.8.68:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
FLANNEL_OPTIONS="" #这里可以指定哪个网卡-iface=ens192
配置k8s /etc/kubernetes/config
[root@kubernetes-node2 ~]# egrep -v "^#|^$" /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://10.64.8.68:8080"
配置kubelet服务 /etc/kubernetes/kubelet
[root@kubernetes-node2 ~]# egrep -v "^#|^$" /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=10.64.8.70" #这个是节点自己的IP
KUBELET_API_SERVER="--api-servers=http://10.64.8.68:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
启动服务
for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
查看每个k8s node上的iflannel ip
查询相关节点
[root@kubernetes-master ~]# kubectl get nodes
NAME STATUS AGE
10.64.8.69 Ready 5d
10.64.8.70 Ready 5d
10.64.8.72 Ready 5d
创建pod测试
mkdir pods
cd pods
vim mysql.yaml
1 apiVersion: v1 2 kind: Pod 3 metadata: 4 name: mysql 5 labels: 6 name: mysql 7 spec: 8 containers: 9 - resources: 10 limits : 11 cpu: 1 12 image: mysql 13 name: mysql 14 env: 15 - name: MYSQL_ROOT_PASSWORD 16 # change this 17 value: yourpassword 18 ports: 19 - containerPort: 3306 20 name: mysql
创建pod
kubectl create -f mysql.yaml
查看pod
[root@kubernetes-master ~]# kubectl get pods
创建 Creating Service
1 apiVersion: v1 2 kind: Service 3 metadata: 4 labels: 5 name: mysql 6 name: mysql 7 spec: 8 externalIPs: 9 - 10.64.8.69 10 ports: 11 # the port that this service should serve on 12 - port: 3306 13 # label keys and values that must match in order to receive traffic for this service 14 selector: 15 name: mysql
kubectl create -f mysql-service.yaml
查询service
[root@kubernetes-master ~]# kubectl get services
数据库容器连接测试