安装kubernetes
准备一台centos7 1) 关闭firewalld 和 selinux systemctl stop firewalld systemctl disable firewalld setenforce 0 2)安装etcd和kubernetes yum install -y etcd kubernetes 3)修改配置文件 vi /etc/sysconfig/docker 将--selinux-enabled 改为 --selinux-enabled=false --insecure-registry gcr.io vi /etc/kubernetes/apiserver 把--admission_control参数中的ServiceAccount删除 4)准备工作 yum install python-rhsm-certificates 如果提示python-rhsm-certificates-1.19.10-1.el7_4.x86_64 被已安装的 subscription-manager-rhsm-certificates- 1.20.11-1.el7.centos.x86_64 取代 wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10- 1.el7_4.x86_64.rpm rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm |cpio -iv --to-stdout ./etc/r hsm/ca/redhat- uep.pem > /etc/r hsm/ca/redhat-uep.pem 配置docker加速器 vi /etc/docker/daemon.json//加入如下内容 { "registry-mirrors": ["https://dhq9bx4f.mirror.aliyuncs.com"] } 5)按顺序启动所有服务 for s in etcd docker kube-apiserver kube-controller-manager kube-scheduler kubelet kube-proxy do systemctl start $s done 6)创建一个rc文件vim mysql-rc.yaml
apiVersion: v1kind: ReplicationControllermetadata: name: mysqlspec: replicas: 1 selector: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.6 ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD value: "123456"
docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
docker pull mysql:5.6 kubectl create -f mysql-rc.yaml kubectl get rc kubectl get pods 7)创建一个svc文件 vim mysql-svc.yamlapiVersion: v1kind: Servicemetadata: name: mysqlspec: ports: - port: 3306 selector: app: mysql
kubectl create -f mysql-svc.yaml kubectl get svc 8)创建web rc文件 vim web-rc.yaml
kind: ReplicationControllermetadata: name: mywebspec: replicas: 1 selector: app: myweb template: metadata: labels: app: myweb spec: containers: - name: myweb image: kubeguide/tomcat-app:v1 ports: - containerPort: 8080 env: - name: MYSQL_SERVICE_HOST value: '10.254.170.174' #这里的IP需要通过kubectl get svc 查看mysql的cluster ip - name: MYSQL_SERVICE_PORT value: '3306'
[root@weifeng04 ~]# kubectl get svcNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes 10.254.0.1443/TCP 3dmysql 10.254.170.174 3306/TCP 3d
kubectl create -f web-rc.yaml 9)创建web svc文件 vim web-svc.yamly
kind: Servicemetadata: name: mywebspec: type: NodePort ports: - port: 8080 nodePort: 30001 selector: app: myweb
kubectl create -f web-svc.yaml
10)访问 iptables -P FORWARD ACCEPT curl 本机ip:30001/demo/ 或浏览器[root@weifeng04 ~]# curl 192.168.20.99:30001/demo/HPE University Docker&Kubernetes Learning Congratulations!!