• kubernetes部署nginx/tomcat


    kubernetes集群已经部署好了,需要的话可以参考之前的文章https://www.cnblogs.com/winter1519/p/10015420.html

    [root@master tomcat]# kubectl get nodes
    NAME      STATUS    AGE
    node1     Ready     10d
    node2     Ready     10d
    部署nginx

    需要三个配置文件:

    [root@master nginx]# vim nginx-pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx-pod
      labels:
        name: nginx-pod
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

    [root@master nginx]# vim nginx-rc.yaml
    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: nginx-rc
    spec:
      replicas: 2
      selector:
        name: nginx-pod
      template:
        metadata:
          labels:
            name: nginx-pod
        spec:
           containers:
           - name: nginx-pod
             image: nginx
             ports:
             - containerPort: 80

    [root@master nginx]# vim nginx-pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx-pod
      labels:
        name: nginx-pod
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

    [root@master nginx]#kubectl create -f nginx-pod.yaml
    [root@master nginx]#kubectl describe pod nginx
    [root@master nginx]#kubectl create -f   nginx-rc.yaml
    [root@master nginx]#kubectl create -f   nginx-service.yaml
    [root@master nginx]# kubectl get pods -o wide
    NAME                        READY     STATUS    RESTARTS   AGE       IP            NODE
    nginx-pod                   1/1       Running   1          1d        10.255.95.2   node2
    nginx-rc-351xd              1/1       Running   1          1d        10.255.1.3    node1
    [root@master nginx]# kubectl get svc
    NAME            CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
    kubernetes      10.254.0.1       <none>        443/TCP          10d
    nginx-service   10.254.208.231   <nodes>       80:30011/TCP     1d
    [root@master nginx]# kubectl get rc
    NAME       DESIRED   CURRENT   READY     AGE
    nginx-rc   2         2         2         1d
    访问nginx:
    http://192.168.91.26:30011

    http://192.168.91.27:30011

    部署tomcat

    [root@master tomcat]# vim tomcat-deployment.yaml
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: my-tomcat
    spec:
      replicas: 2
      template:
        metadata:
          labels:
            app: my-tomcat
        spec:
          containers:
          - name: my-tomcat
            image: docker.io/tomcat
            ports:
            - containerPort: 80


    [root@master tomcat]# vim tomcat-service.yaml
    apiVersion: v1
    kind: Service
    metadata:
      name: my-tomcat
    spec:
      type: NodePort
      ports:
      - port: 8080
        targetPort: 8080
        nodePort: 31111
      selector:
        app: my-tomcat

    [root@master tomcat]# kubectl create -f tomcat-deployment.yaml
    [root@master tomcat]# kubectl create -f tomcat-service.yaml

    [root@master tomcat]# kubectl get deployment
    NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    my-tomcat   2         2         2            2           59m
    [root@master tomcat]# kubectl get svc
    NAME            CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
    kubernetes      10.254.0.1       <none>        443/TCP          10d
    my-tomcat       10.254.110.240   <nodes>       8080:31111/TCP   59m
    nginx-service   10.254.208.231   <nodes>       80:30011/TCP     1d
    [root@master tomcat]# kubectl get pods -o wide
    NAME                        READY     STATUS    RESTARTS   AGE       IP            NODE
    my-tomcat-464109745-ctmdf   1/1       Running   0          1h        10.255.1.5    node1
    my-tomcat-464109745-wmxpz   1/1       Running   0          1h        10.255.95.4   node2
    nginx-pod                   1/1       Running   1          1d        10.255.95.2   node2
    nginx-rc-351xd              1/1       Running   1          1d        10.255.1.3    node1
    访问tomcat
    http://192.168.91.26:31111

    http://192.168.91.27:31111

  • 相关阅读:
    Android 4编程入门经典—开发智能手机与平板电脑应用
    硅谷产学研的创新循环
    用集群实现网格计算
    用商业模式改变世界(上)
    wrox经典红皮书:C++高级编程(第2版)
    编程导师Ivor Horton新作《Java 7入门经典》即将出版
    诚聘译者,翻译有奖!您就是引领先进技术潮流的先驱!
    定义目录的格式
    关于Q+
    Resource and Performance Tradeoffs in DelayTolerant Wireless Networks
  • 原文地址:https://www.cnblogs.com/winter1519/p/11220425.html
Copyright © 2020-2023  润新知