部署web-rc:web應用須要去獲取redis注入的ip環境變量cluster_ip,以此來訪問java
[root@sdw1 files]# cat testweb-rc.yaml kind: ReplicationController metadata: name: testweb spec: replicas: 1 selector: app: testweb template: metadata: labels: app: testweb spec: containers: - name: testweb image: 10.10.18.19:5000/testweb #倉庫鏡像,或者其餘本地鏡像 ports: - containerPort: 8080
部署web-svc:注意label和selector對應node
[root@sdw1 files]# cat testweb-svc.yaml apiVersion: v1 kind: Service metadata: name: testweb spec: type: NodePort ports: - port: 8080 nodePort: 31001 selector: app: testweb
部署redis-rc.yaml:web
[root@sdw1 files]# cat redis-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: redis spec: replicas: 1 selector: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis ports: - containerPort: 6379
部署redis-svc.yamlredis
[root@sdw1 files]# cat redis-svc.yaml apiVersion: v1 kind: Service metadata: name: redis spec: type: NodePort selector: app: redis clusterIP: 100.100.100.100 ports: - name: "1" port: 6379 protocol: TCP targetPort: 6379 nodePort: 31009
依次執行便可:docker
kubectl create -f testweb-rc.yaml kubectl create -f testweb-svc.yaml kubectl create -f redis-rc.yaml kubectl create -f redis-svc.yaml
此時查看pod應該都在正常運行了,web也能夠訪問redis.api
使用kubernetes前最好安裝dashboard,看東西更方便,安裝也很簡單,也是建立三個資源:app
建立空間:this
[root@sdw1 templates]# cat kube-namespace.yaml apiVersion: v1 kind: Namespace metadata: name: kube-system
建立rc:spa
[root@sdw1 templates]# cat kube-dashboard-rc.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: # Keep the name in sync with image version and # gce/coreos/kube-manifests/addons/dashboard counterparts name: kubernetes-dashboard-latest namespace: kube-system spec: replicas: 1 template: metadata: labels: k8s-app: kubernetes-dashboard version: latest kubernetes.io/cluster-service: "true" spec: containers: - name: kubernetes-dashboard image: docker.io/mritd/kubernetes-dashboard-amd64 resources: # keep request = limit to keep this container in guaranteed class limits: cpu: 100m memory: 50Mi requests: cpu: 100m memory: 50Mi ports: - containerPort: 9090 args: - --apiserver-host=http://master:8080 livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30
建立svc:server
[root@sdw1 templates]# cat kube-dashboard-svc.yaml apiVersion: v1 kind: Service metadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" spec: selector: k8s-app: kubernetes-dashboard ports: - port: 80 targetPort: 9090
依次執行:
kubectl create -f kube-namespace.yaml kubectl create -f kube-dashboard-rc.yaml kubectl create -f kube-dashboard-svc.yaml
完