k8s之federation

集群信息

角色 版本 节点 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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容