kubernates hello world
1 关闭防火墙
$systemctl disable firewalld
$systemctl stop firewalld
2 安装etcd 和 kubernates
$yum install -y etcd kubernates
3 修改配置
docker /etc/sysconfig/docker
OPTIONS='--registry-mirror=http://06ec3c30.m.daocloud.io --selinux-enabled=false --insecure-registry gcr.io'
kubernetes apiserver /etc/kubernates/apiserver
--admission-control 参数中的ServiceAccount 删除
4 顺序启动
$systemctl start etcd $systemctl start docker $systemctl start kube-apiserver $systemctl start kube-controller-manager $systemctl start kube-scheduler $systemctl start kubelet $systemctl start kube-proxy
单机版k8s 搭建完成
Hello word 留言板系统
依赖三个镜像:
docker.io/kubeguide/guestbook-php-frontend WEB前端
docker.io/kubeguide/redis-master 写留言
docker.io/kubeguide/guestbook-redis-slave 读取留言
1 创建master pod 和服务
编写 redis-master-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: redis-master labels: name: redis-master spec: replicas: 2 selector: name: redis-master template: metadata: labels: name: redis-master spec: containers: - name: master image: kubeguide/redis-master ports: - containerPort: 6379
发布到k8s集群
$kubectl create -f redis-master-controller.yaml
查看
$kubectl get rc CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE redis-master master kubeguide/redis-master name=redis-master 1 21d $kubectl get po NAME READY STATUS RESTARTS AGE redis-master-69j7a 1/1 Running 7 20d
创建与之对应的service
编写 redis-master-service.yaml
apiVersion: v1 kind: Service metadata: name: redis-master labels: name: redis-master spec: ports: - port: 6379 targetPort: 6379 selector: name: redis-master
$kubectl create -f redis-master-service.yaml $kubectl get svc NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE redis-master 10.254.38.83 <none> 6379/TCP name=redis-master 20d
2 创建redis-salve Pod 和服务
编写 redis-slave-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: redis-slave labels: name: redis-slave spec: 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
发布到k8s集群
$kubectl create -f redis-slave-controller.yaml $kubectl get rc $kubectl get pod
创建 与之对应的service
编写 redis-slave-service.yaml
apiVersion: v1 kind: Service metadata: name: redis-slave labels: name: redis-slave spec: ports: - port: 6379 selector: name: redis-slave
$kubectl create -f redis-slave-service.yaml $kubectl get svc
3 创建frontend Pod 和服务
编写 frontend-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: frontend labels: name: frontend spec: 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
发布到k8s集群
$kubectl create -f frontend-controller.yaml $kubectl get rc $kubectl get pod
创建与之对应的service
编写 frontend-service.yaml
apiVersion: v1 kind: Service metadata: name: frontend labels: name: fronted spec: type: NodePort ports: - port: 80 nodePort: 30001 selector: name: frontend
创建服务
$kubectl create -f frontend-service.yaml
查看
$kubectl get svc
4 通过浏览器访问
localhost:30001
备注 k8s需要容器 gcr.io/google_containers/pause