k8s之federation

2018-12-13  本文已影响0人  xiao_b4b1

集群信息

角色 版本 节点 IP
cluster192 kubernets 1.13.0 master-192 172.30.81.192
cluster194 kubernets 1.12.3 node-194,master-193 172.30.81.193,172.30.81.194
federation kubefed v1.9.0-alpha.3 ; kubectl v1.10.0 主集群cluster192
[root@master-192 kube-calico]# kubectl config get-contexts 
CURRENT   NAME      CLUSTER      AUTHINFO               NAMESPACE
*         c192      cluster192   kubernetes-admin-192   
          c194      cluster194   kubernetes-admin-194   

[root@master-192 kube-calico]# kubectl get node --context=c192
NAME         STATUS    ROLES     AGE       VERSION
master-192   Ready     master    5m        v1.13.0

[root@master-192 kube-calico]# kubectl get node --context=c194
NAME       STATUS    ROLES     AGE       VERSION
node-193   Ready     worker    14d       v1.12.3
ubuntu     Ready     master    14d       v1.12.3

安装federation集群

1.kubefed初始化集群

[root@master-192 kube-calico]# cat /root/federation/coredns-provider.conf 
[Global]
etcd-endpoints = http://172.30.81.192:2379
zones = xiaotech.com.
coredns-endpoints = 10.96.0.10:53
[root@master-192 kube-calico]# kubefed init federation \
>   --host-cluster-context=c192 \
>   --dns-provider="coredns" \
>   --dns-zone-name="xiaotech.com." \
>   --apiserver-enable-basic-auth=true \
>   --apiserver-enable-token-auth=true \
>   --dns-provider-config="/root/federation/coredns-provider.conf" \
>   --apiserver-arg-overrides="--anonymous-auth=false,--v=4" \
>   --api-server-service-type="NodePort" \
>   --api-server-advertise-address="172.30.81.192" \
>   --image=docker.io/xiaotech/fcp-amd64:v1.9.0-alpha.3 \
>   --etcd-image=registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.1.12 \
>   --etcd-persistent-storage=false
Creating a namespace federation-system for federation system components... done
Creating federation control plane service... done
Creating federation control plane objects (credentials, persistent volume claim)...Creating federation component deployments... done
Updating kubeconfig... done
Waiting for federation control plane to come up...... done
Federation API server is running at: 172.30.81.192:32709

2.查看federation的相关信息

新建了federation-system的namespace

[root@master-192 kube-calico]# kubectl get ns
NAME                STATUS    AGE
default             Active    8m
federation-system   Active    1m
kube-public         Active    8m
kube-system         Active    8m

该namespace下有apiserver和controller-manager两个deploy

[root@master-192 federation]# kubectl -n federation-system get deploy
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
apiserver            1         1         1            1           8m
controller-manager   1         1         1            1           8m

新加了apiserver的service ,federation的context可以看到对应接口

[root@master-192 federation]# kubectl -n federation-system get svc
NAME        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
apiserver   NodePort   10.104.202.7   <none>        443:31082/TCP   8m

[root@master-192 federation]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: REDACTED
    server: https://172.30.81.192:6443
  name: cluster192
- cluster:
    certificate-authority-data: REDACTED
    server: https://172.30.81.194:6443
  name: cluster194
- cluster:
    certificate-authority-data: REDACTED
    server: https://172.30.81.192:31082
  name: federation

查看集群信息

[root@master-192 federation]# kubectl get cluster --context=federation
No resources found.

当前集群空,我们只是把federation的控制组件部署在了cluster192中

3.federation添加集群

添加192集群

[root@master-192 kube-calico]# kubefed join cluster192 --cluster-context=c192 --host-cluster-context=c192  --context=federation
cluster "cluster192" created
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# kubectl get cluster --context=federation 
NAME         AGE
cluster192   7s

[root@master-192 kube-calico]# kubefed join cluster194 --host-cluster-context=c192 --cluster-context=c194  --context=federation
cluster "cluster194" created
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# kubectl get cluster --context=federation 
NAME         AGE
cluster192   17s
cluster194   8s

4.修改默认的context为federation

[root@master-192 kube-calico]# kubectl config use-context federation 
Switched to context "federation".
[root@master-192 kube-calico]# kubectl config get-contexts 
CURRENT   NAME         CLUSTER      AUTHINFO               NAMESPACE
          c192         cluster192   kubernetes-admin-192   
          c194         cluster194   kubernetes-admin-194   
*         federation   federation   federation    

验证federation的使用

1.创建deploy
默认的defaut不存在,首先创建

[root@master-192 kube-calico]# kubectl create ns default
[root@master-192 kube-calico]# kubectl get ns
NAME      STATUS    AGE
default   Active    39s
[root@master-192 kube-calico]# kubectl run  nginx --image=nginx --port=80
deployment.apps "nginx" created

查看deploy在集群的分布情况,都分布到集群192上了

[root@master-192 kube-calico]# kubectl get deploy --context=c194
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     0         0         0            0           2m
[root@master-192 kube-calico]# kubectl get deploy --context=c192
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     1         1         1            1           2m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     1         1         1            1           2m

修改deploy的replicas,再查看分布情况

[root@master-192 kube-calico]# kubectl scale --replicas=4 deploy nginx
deployment.extensions "nginx" scaled

可以看到均匀分布

[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         4         4            3           3m
[root@master-192 kube-calico]# kubectl get deploy --context=c192
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            2           4m
[root@master-192 kube-calico]# kubectl get deploy --context=c194
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            1           4m

删除某个集群的deploy,查看如何变化

[root@master-192 kube-calico]# kubectl delete deploy nginx --context=c192
deployment.extensions "nginx" deleted

可以看到过会儿集群又会重新分布

root@master-192 kube-calico]# kubectl get deploy --context=c194
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            1           4m
[root@master-192 kube-calico]# kubectl get deploy --context=c192
No resources found.
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         2         2            1           4m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         2         2            1           4m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         2         2            1           4m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         2         2            1           5m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         4         4            1           5m
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         4         4            1           5m
[root@master-192 kube-calico]# kubectl get deploy --context=c192
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     3         3         3            1           20s
[root@master-192 kube-calico]# kubectl get deploy --context=c194
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     1         1         1            1           5m
[root@master-192 kube-calico]# kubectl get deploy --context=c192
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     3         3         3            3           30s
[root@master-192 kube-calico]# kubectl get deploy --context=federation 
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     4         4         4            4           5m

2.创建service

[root@master-192 kube-calico]# kubectl expose deploy nginx --type=NodePort
service "nginx" exposed
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# 
[root@master-192 kube-calico]# kubectl get svc --context=federation 
NAME      TYPE       CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
nginx     NodePort   <none>       <none>        80/TCP    9s
[root@master-192 kube-calico]# kubectl get svc --context=c192
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        36m
nginx        NodePort    10.98.155.166   <none>        80:32294/TCP   14s
[root@master-192 kube-calico]# kubectl get svc --context=c194
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        14d
nginx        NodePort    10.102.186.190   <none>        80:30107/TCP   19s
上一篇下一篇

猜你喜欢

热点阅读