KUBERNETES DEPLOYMENT

After you install the kubernetes and make the Master and the Worker Next, you can take a test to test whether kubernetes has been executed and the deployed of the network is successfully established or no, Now, we will create a deployment, through httpd images, named myweb. and provide 80 port for httpd deployment of myweb, and before you run the command, download the file here for this page guidance.

Run the command below,

  • kubectl create deployment myweb --image=httpd

    kubectl expose deployment myweb --type="NodePort" --port=80

  • There two types of port which are NodePort that connected to the external network and ClusterPort that used by cluster.

    After that, you can always use command to see the pod kubectl get pods , command to see the service kubectl get svc and to see the kubernetes deployment kubectl get deployment

    Now try the command below to change the number of copies available scale

    • kubectl scale deployment myweb --replicas 3

    • When you generate a deployment, only one pod will be generated by default, so you can use scale to change the number

      Kubernetes Rolling Updates

      As like as Docker Swarm, Kubernetes also supports rolling update and rolling back functions as well. So we first create a httpd deployment, the version chooses the older 2.4.43 version by the following command below,

      • kubectl create deployment myweb1 --image=httpd:2.4.43

      • Now you have made the Image : httpd:2.4.43. After you see the status to create the pods, Now If you want to confirm whether the version is the specified version, you can use describe this following command,

        • kubectl describe pod yourpodname

        • Before starting the rolling update, If you don’t know what the container name, the name after you run the command below is the name of container is, use -o yaml find it by,

          • kubectl get deployment myweb1 -o yaml | grep name

          • Now, you can perform a rolling update to 2.4.46 version, by the command,

            • kubectl set image deployment myweb1 httpd=httpd:2.4.46

            • The result comparation, you can see by the command describe , is the way to see the version is updated to version 2.4.46

              Rollback Function

              • kubectl rollout undo deployment myweb1

              • At this point, your httpd version has reverted to the previous version 2.4.43

                KUBERNETES NAMESPACE

                Follow the command below, to see the namespace

                • kubectl get ns

                  kubectl get namespace

                • One of the kube-system is called namespace, which stores all the kubernetes pod , follow the command below,

                  • kubectl get pods -n kube-system

                  • # -n means namespace

                    Now we can create your own namespace

                    • kubectl create ns yournamespace

                    • Now, you can create a httpd deployment, and specify the storage namespace in yournamespace

                      • kubectl create deployment myweb2 --image=httpd -n yournamespace

                        kubectl create deployment myweb2 --image=httpd -n=yournamespace

                        kubectl get deployments -n yournamespace

                      • Then you can test, test separately kubectl get deployment and kubectl get deployment -n yournamespace

                        If successful, you can go to the master side to check with command kubectl get nodes means to view node status, Now, you can see all namespace by following command,

                        • kubectl get pods --all-namespace

                          kubectl get deployment --all-namespace

                        At last, you can use the container pods to execute of the instructions, you can run the command below,

                        • kubectl exec -it yournamepods -- date

                          kubectl exec -it yournamepods -- echo "hi"

                        The result will depend on after -- that means the function is to let kubernetes process the instructions.