本文共 6258 字,大约阅读时间需要 20 分钟。
dhcpdns.lab.example.com 192.168.0.5 dhcp+dns+ntpserverc.lab.example.com 192.168.0.30 as a master serverservera.lab.example.com 192.168.0.10 serverb.lab.example.com 192.168.0.20
servera and serverb and serverc disable firewalld
[root@server]# yum -y install docker
[root@server]# systemctl enable docker && systemctl start docker
vim /etc/docker/daemon.json
{ "registry-mirrors": ["https://0i5z79j3.mirror.aliyuncs.com"] }
systemctl daemon-reload && systemctl restart docker
[root@serverc ~]# vi /etc/yum.repos.d/virt7-testing.repo
[virt7-testing]name=virt7-testingbaseurl=http://cbs.centos.org/repos/virt7-docker-el-testing/x86_64/os/gpgcheck=0
[root@server]# yum -y install --enablerepo=virt7-testing kubernetes
[root@server]# yum -y install
[root@server]# vi /etc/kubernetes/config
KUBE_MASTER="--master=http://serverc.lab.example.com:8080"KUBE_ETCD_SERVERS="--etcd_servers=http://serverc.lab.example.com:4001"
[root@serverc yum.repos.d]# vi /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"KUBE_API_PORT="--port=8080"# KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
[root@serverc yum.repos.d]# ps -efw|grep kube
[root@servera ~]# vi /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"KUBELET_PORT="--port=10250"KUBELET_HOSTNAME="--hostname-override=servera.lab.example.com"KUBELET_API_SERVER="--api_servers=http://serverc.lab.example.com:8080"
No API token found for service account "default", retry after the token is automatically created and added to the service account
解决办法是去除认证编辑/etc/kubernetes/apiserver 去除 KUBE_ADMISSION_CONTROL中的SecurityContextDeny,ServiceAccount并重启kube-apiserver.service服务[root@serverc ymal-pod]# systemctl restart kube-apiserver.service
[root@serverc pod-yaml]# kubectl get nodes
apiVersion: v1kind: ReplicationControllermetadata: name: redis-master labels: name: redis-masterspec: replicas: 1 selector: name: redis-master template: metadata: labels: name: redis-master spec: containers: - name: master image: kubeguide/redis-master ports: - containerPort: 6379
[root@serverc pod-yaml]# vi redis-master.yaml
apiVersion: v1 kind: Service metadata: name: redis-master labels: name: redis-master spec: ports: - port: 6379 targetPort: 6379 selector: name: redis-master
[root@serverc ymal-pod]# kubectl describe pod redis-master-jr638需要在节点(node)上安装[root@serverc ymal-pod]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest[root@serverc ymal-pod]# yum install *rhsm*
[root@serverc ymal-pod]# vi redis-service.yaml
apiVersion: v1kind: Servicemetadata: name: redis-master labels: name: redis-masterspec: ports: - port: 6379 targetPort: 6379 selector: name: redis-master
[root@serverc ymal-pod]# kubectl create -f redis-service.yaml
[root@serverc ymal-pod]# kubectl get pods -o wide
[root@serverc ymal-pod]# vi redis-slave.yaml
apiVersion: v1kind: ReplicationControllermetadata: name: redis-slave labels: name: redis-slavespec: replicas: 2 selector: name: redis-slave template: metadata: labels: name: redis-slave spec: containers: - name: slave image: kubeguide/guestbook-redis-slave env: - name: GET_HOSTS_FROM value: env ports: - containerPort: 6379
[root@serverc ymal-pod]# vi redis-slave-service.yaml
apiVersion: v1kind: Servicemetadata: name: redis-slave labels: name: redis-slavespec: ports: - port: 6379 selector: name: redis-slave
实现redis集群的主从数据同步, redis-slave需要知道redis-master的地址,所以在redis-slave镜像的启动命令/run.sh 中,可以看到如下内容:
redis-server --slaveof ${REDIS_MASTER_SERVICE_HOST} 6379[root@serverc ymal-pod]# vi frontend-pod.yaml
apiVersion: v1kind: ReplicationControllermetadata: name: frontend labels: name: frontendspec: replicas: 3 selector: name: frontend template: metadata: labels: name: frontend spec: containers: - name: frontend image: kubeguide/guestbook-php-frontend env: - name: GET_HOSTS_FROM value: env ports: - containerPort: 80
[root@serverc ymal-pod]# vi frontend-service.yaml
Version: v1kind: Servicemetadata: name: frontend labels: name: frontendspec: type: NodePort ports: - port: 80 nodePort: 30001 selector: name: frontend
[root@serverc pod-yaml]# kubectl create -f frontend-service.yaml
[root@serverc ymal-pod]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODEfrontend-22b67 1/1 Running 0 4m 172.17.0.3 servera.lab.example.comfrontend-lksvk 1/1 Running 0 4m 172.17.0.4 serverb.lab.example.comfrontend-v81wh 1/1 Running 0 4m 172.17.0.4 servera.lab.example.comredis-master-xbkwj 1/1 Running 0 51m 172.17.0.2 serverb.lab.example.comredis-slave-cqj43 1/1 Running 0 32m 172.17.0.2 servera.lab.example.comredis-slave-q1q4j 1/1 Running 0 32m 172.17.0.3 serverb.lab.example.com
[root@serverc ymal-pod]# kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEfrontend 10.254.127.11180:30001/TCP 21skubernetes 10.254.0.1 443/TCP 1hredis-master 10.254.20.7 6379/TCP 42mredis-slave 10.254.156.197 6379/TCP 29m
firefox:
转载于:https://blog.51cto.com/11732619/2065102