1.下载镜像
docker pull docker.io/kubeguide/guestbook-php-frontend docker pull docker.io/kubeguide/redis-master docker pull docker.io/kubeguide/guestbook-redis-slave
2.修改配置文件
/etc/kubernetes/apiserver中删除ServiceAccount KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ServiceAccount,SecurityContextDeny,ResourceQuota"修改vi /etc/sysconfig/docker中修改OPTIONS选项OPTIONS=‘--selinux-enabled=false --insecure-registry gcr.io‘
3.创建redis-master Pod和服务
kubectl create -f redis-master-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: redis-master labels: name: redis-master spec: replicas: 1 selector: name: redis-master template: metadata: labels: name: redis-master spec: containers: - name: master image: docker.io/kubeguide/redis-master ports: - containerPort: 6379
kubectl create -f 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
4.创建redis-slave Pod和服务
kubectl create -f redis-slave-rc.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: docker.io/kubeguide/guestbook-redis-slave env: - name: GET_HOSTS_FROM value: env ports: - containerPort: 6379
kubectl create -f redis-slave-service.yaml apiVersion: v1 kind: Service metadata: name: redis-slave labels: name: redis-slave spec: ports: - port: 6379 selector: name: redis-slave
5.创建frontend Pod和服务
kubectl create -f frontend-rc.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: docker.io/kubeguide/guestbook-php-frontend env: - name: GET_HOSTS_FROM value: env ports: - containerPort: 6379
kubectl create -f frontend-service.yaml apiVersion: v1 kind: Service metadata: name: frontend labels: name: frontend spec: type: NodePort ports: - port: 80 nodePort: 30001 selector: name: frontend
6.查看pods,svc,rc
kubectl get rc CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE frontend frontend docker.io/kubeguide/guestbook-php-frontend name=frontend 3 2h redis-master master docker.io/kubeguide/redis-master name=redis-master 1 6h redis-slave slave docker.io/kubeguide/guestbook-redis-slave name=redis-slave 2 6h kubectl get svc NAME LABELS SELECTOR IP(S) PORT(S) AGE frontend name=frontend name=frontend 10.254.71.174 80/TCP 2h kubernetes component=apiserver,provider=kubernetes <none> 10.254.0.1 443/TCP 4d redis-master name=redis-master name=redis-master 10.254.164.159 6379/TCP 3h redis-slave name=redis-slave name=redis-slave 10.254.165.215 6379/TCP 3h kubectl get pods NAME READY STATUS RESTARTS AGE frontend-48fgc 1/1 Running 1 -24730s frontend-lhcbc 1/1 Running 0 -24730s frontend-vkex0 1/1 Running 0 -24730s redis-master-dr1nc 1/1 Running 1 -21280s redis-slave-d5z5j 1/1 Running 1 -21280s redis-slave-we0qp 1/1 Running 0 -21280s
7.访问http://192.168.42.128:30001/
时间: 2024-11-08 09:12:19