环境

软件版本
centos7.4-1708
docker18.03.0-ce
kubernetes1.17.0

K8S集群搭建

https://blog.csdn.net/zz_aiytag/article/details/103816076

拉取Hadoop镜像

[root@manager ~]# docker pull kubeguide/hadoop:latest
latest: Pulling from kubeguide/hadoop
c60055a51d74: Pull complete 
755da0cdb7d2: Pull complete 
969d017f67e6: Pull complete 
37c9a9113595: Pull complete 
a3d9f8479786: Pull complete 
aa4492917106: Pull complete 
8148ceb323cf: Pull complete 
22933d212317: Pull complete 
2ca54e15be53: Pull complete 
93e2ce53f914: Pull complete 
517d2bf12034: Pull complete 
05c29137fa8e: Pull complete 
Digest: sha256:86211353b0380a4cab4a12bfd016754df29d1b30c871ac17d91d7096786b63f0
Status: Downloaded newer image for kubeguide/hadoop:latest

一个节点下载完成后,导出,拷贝到另两个节点

[root@manager ~]# docker save e0af06208032 > kubeguide-hadoop.tar
[root@manager ~]# ll
total 829484
-rw-------. 1 root root      1500 Apr  2 08:46 anaconda-ks.cfg
-rw-r--r--  1 root root     14366 May 26 14:11 kube-flannel.yml
-rw-r--r--  1 root root 849371136 May 28 10:33 kubeguide-hadoop.tar

拷贝

[root@manager ~]# scp kubeguide-hadoop.tar master.rancher:$PWD
kubeguide-hadoop.tar                                                                                                                                                                                                                        100%  810MB   9.9MB/s   01:22    
[root@manager ~]# scp kubeguide-hadoop.tar worker.rancher:$PWD
kubeguide-hadoop.tar 

另外两个节点导入

[root@master ~]# docker load < kubeguide-hadoop.tar 
918b1e79e358: Loading layer [==================================================>]  196.9MB/196.9MB
83b575865dd1: Loading layer [==================================================>]  209.9kB/209.9kB
153bd22a8e96: Loading layer [==================================================>]  7.168kB/7.168kB
ca893d4b83a6: Loading layer [==================================================>]  4.608kB/4.608kB
c9fc7024b484: Loading layer [==================================================>]  3.072kB/3.072kB
158827c96b82: Loading layer [==================================================>]  401.7MB/401.7MB
014211a6c460: Loading layer [==================================================>]  250.5MB/250.5MB
836c1279a52e: Loading layer [==================================================>]   5.12kB/5.12kB
a8d63a3b1f08: Loading layer [==================================================>]  24.06kB/24.06kB
57a812a8ca9d: Loading layer [==================================================>]   21.5kB/21.5kB
060b107687aa: Loading layer [==================================================>]  4.608kB/4.608kB
0b40597187a3: Loading layer [==================================================>]  7.168kB/7.168kB
Loaded image ID: sha256:e0af0620803289e619f0605562d4d5d55b0ad7c70b6c4536fa589e4aeb6267f0

编写hdfs.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-hadoop-conf-1  
  namespace: myns1
data:
  HDFS_MASTER_SERVICE: hadoop-hdfs-master
---
apiVersion: v1
kind: Service
metadata:
  # 修改会导致HDFS集群不可用
  name: hadoop-hdfs-master
  namespace: myns1
spec:
  type: NodePort
  selector:
    name: hdfs-master-3
  ports:
    - name: rpc
      port: 9000
      targetPort: 9000
    - name: http
      port: 50070
      targetPort: 50070
      nodePort: 32007
apiVersion: v1
kind: ReplicationController
metadata:
  name: hdfs-master-4
  namespace: myns1
  labels:
    name: hdfs-master-3
spec:
  replicas: 1
  selector:
    name: hdfs-master-3
  template:
    metadata:
      labels:
        name: hdfs-master-3
    spec:
      containers:
        - name: hdfs-master-6
          image: kubeguide/hadoop:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9000
            - containerPort: 50070
          env:
            - name: HADOOP_NODE_TYPE
              value: namenode
            - name: HDFS_MASTER_SERVICE
              valueFrom:
                configMapKeyRef:
                  name: kube-hadoop-conf-1
                  key: HDFS_MASTER_SERVICE
      restartPolicy: Always
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: hadoop-datanode-6
  namespace: myns1
  labels:
    app: hadoop-datanode-7
spec:
  replicas: 3
  selector:
    name: hadoop-datanode-7
  template:
    metadata:
      labels:
        name: hadoop-datanode-7
    spec:
      containers:
        - name: hadoop-datanode-8
          image: kubeguide/hadoop:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9000
            - containerPort: 50070
          env:
            - name: HADOOP_NODE_TYPE
              value: datanode
            - name: HDFS_MASTER_SERVICE
              valueFrom:
                configMapKeyRef:
                  name: kube-hadoop-conf-1
                  key: HDFS_MASTER_SERVICE
      restartPolicy: Always

每个name后面的的序号表明,部分地方的配置是需要名字相同的。

执行启动

创建myns1命名空间

[root@manager ~]# kubectl create namespace myns1
namespace/myns1 created
[root@manager ~]# kubectl get namespace
NAME              STATUS   AGE
default           Active   3d3h
kube-node-lease   Active   3d3h
kube-public       Active   3d3h
kube-system       Active   3d3h
myns1             Active   9s

执行启动

[root@manager ~]# kubectl create -f hdfs.yml
configmap/kube-hadoop-conf-1 created
service/hadoop-hdfs-master-2 created
replicationcontroller/hdfs-master-4 created
replicationcontroller/hadoop-datanode-6 created

查看服务

[root@manager ~]# kubectl get pods,svc -n myns1
NAME                          READY   STATUS    RESTARTS   AGE
pod/hadoop-datanode-6-mbqtn   1/1     Running   0          2m28s
pod/hadoop-datanode-6-t7x5j   1/1     Running   0          2m28s
pod/hadoop-datanode-6-wvwwp   1/1     Running   0          2m28s
pod/hdfs-master-4-5stbn       1/1     Running   0          2m28s

NAME                           TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                          AGE
service/hadoop-hdfs-master   NodePort   10.96.238.218   <none>        9000:32504/TCP,50070:32227/TCP   2m28s

页面访问

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐