目錄node
date: 2019-5-21
author:yangxiaoyi
---linux
系統: centos 7.6
docker: 1.13.1nginx
yum install etcd kubernetes -ygit
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-proxygithub
系統:centos 7
docker: 1.13.1
etcd: 3.3.11
Kubernetes: v1.5.2
apiserver: v1beta1docker
2臺主機作master集羣、etcd集羣、registry集羣
2臺主機作node
192.168.181.146 master1
192.168.181.150 master2
192.168.181.149 node1
192.168.181.147 node2centos
ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://192.168.181.146:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.181.146:2379,http://127.0.0.1:2379" ETCD_NAME="etcd1" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.181.146:2380" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.181.146:2379,http://127.0.0.1:2379" ETCD_INITIAL_CLUSTER="etcd1=http://192.168.181.146:2380,etcd2=http://192.168.181.150:2380"
etcd2主機將配置文件中etcd1改成etcd2api
ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://192.168.181.150:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.181.150:2379,http://127.0.0.1:2379" ETCD_NAME="etcd2" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.181.150:2380" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.181.150:2379,http://127.0.0.1:2379" ETCD_INITIAL_CLUSTER="etcd1=http://192.168.181.146:2380,etcd2=http://192.168.181.150:2380" ETCD_INITIAL_CLUSTER_STATE="new"
啓動服務
systemctl start etcd服務器
測試服務
etcdctl member list負載均衡
參考文檔https://cloud.tencent.com/developer/article/1433266
systemctl start docker-distribution
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" KUBE_API_PORT="--port=8080" KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.181.146:2379,http://192.168.181.150:2379" KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" KUBE_API_ARGS=""
vi /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true" KUBE_LOG_LEVEL="--v=0" KUBE_ALLOW_PRIV="--allow-privileged=false" KUBE_MASTER="--master=http://192.168.181.146:8080"
yum -y install keepalived nginx
upstream kube-master { ip_hash; server master1:8080 weight=3; server master2:8080 weight=2; } server { listen 8001; server_name _; location / { proxy_pass http://kube-master; } }
vi /etc/keepalived/keepalived.conf
[root@master1 ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id node1 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance ka { state MASTER interface ens37 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.181.151 } } virtual_server 192.168.181.151 8001 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.181.146 8001 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.181.150 8001 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
KUBELET_ADDRESS="--address=0.0.0.0" KUBELET_HOSTNAME="--hostname-override=node1" KUBELET_API_SERVER="--api-servers=http://master1:8080,http://master2:8080" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest" KUBELET_ARGS=""
啓動服務並測試
systemctl start kubelet proxy
kubectl get nodes
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false' if [ -z "${DOCKER_CERT_PATH}" ]; then DOCKER_CERT_PATH=/etc/docker fi ADD_REGISTRY='--add-registry master1:5000' INSECURE_REGISTRY='--insecure-registry master1:5000'
kubectl run -i -t bbox --image=busybox
#查看部署 kubectl get deployments #查看pods kubectl get pods
1.安裝flannel
yum install flannel
2.在master和node節點上配置flannel
vi /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://master1:2379,http://master2:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
在etcd上配置flanneld使用的地址池
etcdctl mk /atomic.io/network/config '{"Network":"10.99.0.0/16"}'
在master上啓動flanneld服務
systemctl start flanneld.service
在node節點上啓動flanneld服務,並重啓docker服務便可完成配置
systemctl start flanneld.service
systemctl restart docker.service
測試
略
1.下載yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.5.1/src/deploy/kubernetes-dashboard.yaml
2.修改文件內容
image:gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.1 #注意千萬別用域名,要用ip地址 - --apiserver-host=http://192.168.181.146:8080
kubectl create -f kubernetes-dashboard.yaml