• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

arun-gupta/kubernetes-java-sample: Kubernetes Hands-on Workshop

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

arun-gupta/kubernetes-java-sample

开源软件地址(OpenSource Url):

https://github.com/arun-gupta/kubernetes-java-sample

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource Introduction):

Kubernetes for Java Developers

Create Resources

Pod

Using CLI

  1. Create pod: kubectl run wildfly --image=jboss/wildfly --port=8080

  2. Check status: kubectl get -w pods

    1. Show the pod name derived from the Deployment name

  3. Describe pod: kubectl describe pod <pod-name> or kubectl describe pod/<pod-name>

  4. Get logs: kubectl logs <pod-name>

    1. Use -f to tail logs

  5. Get deployments: kubectl get deployments

  6. Delete deployments: kubectl delete deployments/wildfly

  7. Get deployments: kubectl get deployments

  8. Get pods: kubectl get pods

Using Configuration File

  1. Create pod: kubectl create -f wildfly-pod.yaml

  2. Get pods: kubectl get pods

    1. Wide: kubectl get pods -o wide

    2. YAML: kubectl get pods -o yaml

    3. JSON: kubectl get pods -o json

  3. Describe pod: kubectl describe pod/wildfly-pod

  4. Delete pod: kubectl delete pod/wildfly-pod

  5. Get pods: kubectl get pods

Replication Controller

  1. Create RC: kubectl create -f wildfly-rc.yaml

  2. Get RC: kubectl get rc

  3. Get pods: kubectl get pods

    1. Show pod names

    2. Show image id downloaded on the second host

  4. Get pods created by RC: kubectl describe pods wildfly-rc

  5. Get pods with a specified label: kubectl get pods -l name=wildfly

  6. Delete RC: kubectl delete rc wildfly-rc

Service

  1. Create Service: kubectl create -f wildfly-service.yaml

  2. Get RC, Service and Pods: kubectl get rc,service,pods

  3. Describe service: kubectl describe service wildfly-service

  4. If Kubernetes is on cloud with LB

    1. Get the value of LoadBalancer Ingress, access the WildFly landing page at <IP>:8080

  5. Delete multiple resources: kubectl delete rc/wildfly-rc service/wildfly-service

Load Balancing

  1. ClusterIP: This is default, exposes service on cluster-internal IP.

    1. Create: kubectl create -f lb-clusterip.yaml

    2. Describe: kubectl get svc

      NAME              CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
      kubernetes        100.64.0.1    <none>        443/TCP    48m
      wildfly-service   100.71.85.1   <none>        8080/TCP   13m

      Details: kubectl describe svc wildfly-service

      kubectl describe svc wildfly-service
      Name:			wildfly-service
      Namespace:		default
      Labels:			<none>
      Annotations:		<none>
      Selector:		app=wildfly-rc-pod
      Type:			ClusterIP
      IP:			100.71.85.1
      Port:			web	8080/TCP
      Endpoints:		100.96.1.4:8080,100.96.2.3:8080
      Session Affinity:	None
      Events:			<none>
    3. Access: Service is accessible only inside the cluster.

      1. Expose the service: kubectl expose service wildfly-service --port=8080 --target-port=8080 --name=web

      2. Start Kubernetes proxy: kubectl proxy

      3. Access the service: curl http://localhost:8001/api/v1/proxy/namespaces/default/services/web/index.html

    4. Delete:

      kubectl delete -f lb-clusterip.yaml
      kubectl delete svc/web
  2. NodePort: Expose service on each node of the cluster at a static port.

    1. Create: kubectl create -f lb-nodeport.yaml

    2. Describe: kubectl get svc

      NAME              CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
      kubernetes        100.64.0.1      <none>        443/TCP          2h
      wildfly-service   100.68.222.70   <nodes>       8080:32233/TCP   29m

      Details: kubectl describe svc wildfly-service

      Name:			wildfly-service
      Namespace:		default
      Labels:			<none>
      Annotations:		<none>
      Selector:		app=wildfly-rc-pod
      Type:			NodePort
      IP:			100.68.222.70
      Port:			web	8080/TCP
      NodePort:		web	32233/TCP
      Endpoints:		100.96.1.13:8080,100.96.2.12:8080
      Session Affinity:	None
      Events:			<none>
    3. Access: Service is accessible using <NodeIP>:<NodePort>. <NodePort> for us is 32233.

      1. Configure the worker node firewall to create a Custom TCP Rule to allow port 32233 accessible from Anywhere.

      2. Find IP address of the worker nodes using AWS Console.

      3. Service is accessible at <worker-node-ip>:32233.

    4. Delete: kubectl delete -f lb-nodeport.yaml

  3. LoadBalancer: Expose the service using a cloud provider’s load balancer.

    1. Create: kubectl create -f lb-loadbalancer.yaml

    2. Describe: kubectl get svc

      NAME              CLUSTER-IP       EXTERNAL-IP        PORT(S)          AGE
      kubernetes        100.64.0.1       <none>             443/TCP          2h
      wildfly-service   100.65.225.120   afa8056b14fc9...   8080:30229/TCP   4s

      Details:

      Name:			wildfly-service
      Namespace:		default
      Labels:			<none>
      Annotations:		<none>
      Selector:		app=wildfly-rc-pod
      Type:			LoadBalancer
      IP:			100.65.225.120
      LoadBalancer Ingress:	afa8056b14fc911e79b1906d8a9d4b8c-1413998286.us-west-2.elb.amazonaws.com
      Port:			web	8080/TCP
      NodePort:		web	30229/TCP
      Endpoints:		100.96.1.14:8080,100.96.2.13:8080
      Session Affinity:	None
      Events:
        FirstSeen	LastSeen	Count	From			SubObjectPath	Type		Reason			Message
        ---------	--------	-----	----			-------------	--------	------			-------
        11s		11s		1	service-controller			Normal		CreatingLoadBalancer	Creating load balancer
        8s		8s		1	service-controller			Normal		CreatedLoadBalancer	Created load balancer
    3. Access: Service is accessible at <LoadBalancer-Ingress>:8080. Wait for 3 mins for the load balancer to settle before accessing this URL. Firewall rules are created during the service creation.

    4. Delete: kubectl delete -f lb-loadbalancer.yaml

  4. ExternalName: Returns a CNAME record to an external service running outside the cluster. Allows for pods within the cluster to access the service outside the cluster. Redirection happens at DNS level, with no proxying or forwarding.

    1. Create

      1. Start a WildFly bitnami stack

      2. Get IP address of the provisioned host and replace the value in lb-external.yaml

      3. kubectl create -f lb-external.yaml

    2. Describe: kubectl get svc:

      NAME              CLUSTER-IP   EXTERNAL-IP                                         PORT(S)   AGE
      kubernetes        100.64.0.1   <none>                                              443/TCP   3h
      wildfly-service                ec2-34-210-79-105.us-west-2.compute.amazonaws.com   8080/TCP  2s

      Details: kubectl describe svc/wildfly-service

      Name:			wildfly-service
      Namespace:		default
      Labels:			<none>
      Annotations:		<none>
      Selector:		<none>
      Type:			ExternalName
      IP:
      External Name:		ec2-34-210-79-105.us-west-2.compute.amazonaws.com
      Port:			web	8080/TCP
      Endpoints:		<none>
      Session Affinity:	None
      Events:			<none>
    3. Access: This service is only accessible inside the cluster. kubectl expose only work for services with selectors.

    4. Delete: kubectl delete -f lb-external.yaml

Using Maven (Service + Replication Controller + Client Pod)

All the code is in maven directory:

  1. Create Couchbase service: kubectl create -f couchbase-service.yml

  2. Check status: kubectl get -w pods

  3. Run application: kubectl create -f bootiful-couchbase.yml

  4. Check status: kubectl get -w pods

    1. Show ContainerCreating

  5. Show all pods: kubectl get pods --show-all

  6. Check logs: kubectl logs -f <pod-name> to show the output Book{isbn=978-1-4919-1889-0, name=Minecraft Modding with Forge, cost=29.99}

  7. Delete all resources: kubectl delete -f couchbase-service.yml -f bootiful-couchbase.yml

Rolling Updates

Namespaces

  1. Create a new namespace: kubectl create -f dev-namespace.yaml

  2. Get namespaces: kubectl get namespace

  3. Create a new deployment in the namespace: kubectl --namespace=development run couchbase --image=arungupta/couchbase

  4. List deployments: kubectl get deployments

    1. No deployments shown

  5. List all resources in the namespace: kubectl get deployments --namespace=development

  6. List all resources in all namespaces: kubectl get deployments --all-namespaces

  7. Show pods in the namespaces: kubectl get pods --all-namespaces

Quota (broken)

  1. Create a constrained resource: kubectl create -f quota-wildfly.yaml

  2. Check for pods: kubectl get -w pods

  3. Broken: kubernetes/kubernetes#33621

Run-once/Batch Jobs

  1. Create a job: kubectl create -f runonce-job.yaml

  2. Check jobs: kubectl get jobs

  3. More details about job: kubectl describe jobs wait

  4. Check pods: kubectl get pods

  5. Show all completed pods: kubectl get pods --show-all

Daemon Set (work in progress)

  1. Create a daemon set: kubectl create -f prometheus-dameonset.yml .

Tips

  1. Create resources in all .json, .yaml and .yml files in dir: kubectl create -f ./dir




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap