第十章 在kubernetes 部署第一个应用

最后更新于:2022-04-02 05:07:00

# 实例结构 * * * * * ![](images/bVuweU.png) # 创建redis-master-controller.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: kubeguide/redis-master ports: - containerPort: 6379 发布到kubernetes集群,自动创建pod kubectl create -f redis-master-controller.yaml kubectl get rc kubectl get pods # 创建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 创建service kubectl create -f redis-master-service.yaml kubectl get services # 创建redis-slave-controller.yaml apiVersion: v1 kind: ReplicationController metadata: name: redis-slave spec: replicas: 2 selector: name: redis-slave template: metadata: name: redis-slave labels: name: redis-slave spec: containers: - name: redis-slave image: kubeguide/guestbook-redis-slave env: - name: GET_HOSTS_FROM value: env ports: - containerPort: 6379 创建 redis-slave kubectl create -f redis-slave-controller.yaml kubectl get rc kubectl get pods # 创建redis-slave-service.yaml apiVersion: v1 kind: Service metadata: name: redis-slave labels: name: redis-slave spec: ports: - port: 6379 selector: name: redis-slave 创建 redis-slave service kubectl create -f redis-slave-service.yaml kubectl get services # 创建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 创建 kubectl create -f frontend-controller.yaml kubectl get rc kubectl get pods # 创建frontend-service.yaml apiVersion: v1 kind: Service metadata: name: frontend labels: name: frontend spec: type: NodePort ports: - port: 80 nodePort: 30001 selector: name: frontend 创建 kubectl create -f frontend-service.yaml kubectl get services
';