Skip to content

Commit

Permalink
Merge pull request #56 from banzaicloud/upgrade
Browse files Browse the repository at this point in the history
PKE upgrade
  • Loading branch information
Ecsy authored Jun 24, 2019
2 parents 580c786 + 603ede2 commit a670940
Show file tree
Hide file tree
Showing 57 changed files with 1,158 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/dist/
/vendor/
/pke-single-config.yaml
/pke-multi-config.yaml

**/.vagrant*
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Vagrant.configure("2") do |config|
# sync build folder
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder 'scripts/vagrant/', '/scripts/', create: true
config.vm.synced_folder 'build/', '/banzaicloud/', create: true

$num_instances = 4

Expand Down
26 changes: 26 additions & 0 deletions centos7-multi-upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -e

# build latest pke tool
GOOS=linux make pke

KUBERNETES_VERSION="${1:-v1.14.3}"

# upgrade first master node
echo ""
echo "= node1 ========================================================================"
vagrant ssh node1 -c "sudo /banzaicloud/pke upgrade master --kubernetes-version='$KUBERNETES_VERSION'"

# upgrade second master node
echo ""
echo "= node2 ========================================================================"
vagrant ssh node2 -c "sudo /banzaicloud/pke upgrade master --kubernetes-version='$KUBERNETES_VERSION' --kubernetes-additional-control-plane"

# upgrade third master node
echo ""
echo "= node3 ========================================================================"
vagrant ssh node3 -c "sudo /banzaicloud/pke upgrade master --kubernetes-version='$KUBERNETES_VERSION' --kubernetes-additional-control-plane"

# upgrade worker node
echo ""
echo "= node4 ========================================================================"
vagrant ssh node4 -c "sudo /banzaicloud/pke upgrade worker --kubernetes-version='$KUBERNETES_VERSION'"
51 changes: 51 additions & 0 deletions centos7-multi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash -e

# prerequisitesSkipping phase due to missing Pipeline API endpoint credentials
jq --version || (echo "Please install jq command line tool. https://stedolan.github.io/jq/" && exit 1)

# build latest pke tool
GOOS=linux make pke

KUBERNETES_VERSION="${1:-v1.14.3}"

# install first master node
echo ""
echo "= node1 ========================================================================"
vagrant up node1
vagrant ssh node1 -c "sudo /scripts/pke-multi-master1.sh '$KUBERNETES_VERSION'"
vagrant ssh node1 -c 'sudo cat /etc/kubernetes/admin.conf' > pke-multi-config.yaml
vagrant ssh node1 -c "sudo /banzaicloud/pke token list -o json" > build/token.json

TOKEN=`jq -r '.tokens[] | select(.expired == false) | .token' build/token.json`
CERTHASH=`jq -r '.tokens[] | select(.expired == false) | .hash' build/token.json`

echo ""
echo "Using '$TOKEN' and '$CERTHASH' to join other nodes to the cluster"

# install second master node
echo ""
echo "= node2 ========================================================================"
vagrant up node2
vagrant ssh node2 -c "sudo /scripts/pke-multi-mastern.sh '$KUBERNETES_VERSION' '$TOKEN' '$CERTHASH' 192.168.64.12"

# install third master node
echo ""
echo "= node3 ========================================================================"
vagrant up node3
vagrant ssh node3 -c "sudo /scripts/pke-multi-mastern.sh '$KUBERNETES_VERSION' '$TOKEN' '$CERTHASH' 192.168.64.13"

# install worker node
echo ""
echo "= node4 ========================================================================"
vagrant up node4
vagrant ssh node4 -c "sudo /scripts/pke-multi-worker.sh '$KUBERNETES_VERSION' '$TOKEN' '$CERTHASH'"

export KUBECONFIG=$PWD/pke-multi-config.yaml

echo ""
echo "You can access your PKE cluster either:"
echo "- from your host machine accessing the cluster via kubectl. Please run:"
echo "export KUBECONFIG=$PWD/pke-multi-config.yaml"
echo ""
echo "- or starting a shell in the virtual machine. Please run:"
echo "vagrant ssh node1 -c 'sudo -s'"
8 changes: 8 additions & 0 deletions centos7-single-upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# build latest pke tool
GOOS=linux make pke

KUBERNETES_VERSION="${1:-v1.14.3}"

vagrant ssh node1 -c "sudo /banzaicloud/pke upgrade master --kubernetes-version='$KUBERNETES_VERSION'"
7 changes: 6 additions & 1 deletion centos7-single.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash -e

# build latest pke tool
GOOS=linux make pke

KUBERNETES_VERSION="${1:-v1.14.3}"

vagrant up node1
vagrant ssh node1 -c "sudo /scripts/pke-single.sh"
vagrant ssh node1 -c "sudo /scripts/pke-single.sh '$KUBERNETES_VERSION'"
vagrant ssh node1 -c 'sudo cat /etc/kubernetes/admin.conf' > pke-single-config.yaml

export KUBECONFIG=$PWD/pke-single-config.yaml
Expand Down
1 change: 1 addition & 0 deletions cmd/pke/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewPKECommand(in io.Reader, out io.Writer, gitVersion, gitCommit, gitTreeSt
cmd.AddCommand(NewCmdInstall(out))
cmd.AddCommand(NewCmdImage(out))
cmd.AddCommand(NewCmdToken(out))
cmd.AddCommand(NewCmdUpgrade(out))
cmd.AddCommand(NewCmdVersion(out, gitVersion, gitCommit, gitTreeState, buildDate))

return cmd
Expand Down
71 changes: 71 additions & 0 deletions cmd/pke/app/cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright © 2019 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"io"

"github.com/banzaicloud/pke/cmd/pke/app/phases"
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/upgrade/controlplane"
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/upgrade/node"
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/version"
"github.com/spf13/cobra"
)

func NewCmdUpgrade(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade",
Short: "Upgrade a single Banzai Cloud Pipeline Kubernetes Engine (PKE) machine",
Args: cobra.NoArgs,
RunE: phases.RunEAllSubcommands,
}

cmd.AddCommand(upgradeMaster(out))
cmd.AddCommand(upgradeWorker(out))

return cmd
}

func upgradeMaster(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "master",
Short: "Upgrade a single Banzai Cloud Pipeline Kubernetes Engine (PKE) master machine",
Args: cobra.NoArgs,
RunE: phases.RunEAllSubcommands,
}

cmd.AddCommand(version.NewCommand(out))
cmd.AddCommand(controlplane.NewCommand(out))

phases.MakeRunnable(cmd)

return cmd
}

func upgradeWorker(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "worker",
Short: "Upgrade a single Banzai Cloud Pipeline Kubernetes Engine (PKE) worker machine",
Args: cobra.NoArgs,
RunE: phases.RunEAllSubcommands,
}

cmd.AddCommand(version.NewCommand(out))
cmd.AddCommand(node.NewCommand(out))

phases.MakeRunnable(cmd)

return cmd
}
2 changes: 2 additions & 0 deletions cmd/pke/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const (
FlagClusterMode = "kubernetes-master-mode"
// FlagControlPlaneJoin worker command should install control plane node.
FlagControlPlaneJoin = "kubernetes-join-control-plane"
// FlagAdditionalControlPlane upgrade additional control plane node.
FlagAdditionalControlPlane = "kubernetes-additional-control-plane"

// CloudProviderAmazon Amazon Web Services
CloudProviderAmazon = "aws"
Expand Down
2 changes: 1 addition & 1 deletion cmd/pke/app/phases/kubeadm/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *ControlPlane) Short() string {

func (c *ControlPlane) RegisterFlags(flags *pflag.FlagSet) {
// Kubernetes version
flags.String(constants.FlagKubernetesVersion, "1.14.0", "Kubernetes version")
flags.String(constants.FlagKubernetesVersion, "1.14.3", "Kubernetes version")
// Kubernetes network
flags.String(constants.FlagNetworkProvider, "weave", "Kubernetes network provider")
flags.String(constants.FlagAdvertiseAddress, "", "Kubernetes API Server advertise address")
Expand Down
2 changes: 1 addition & 1 deletion cmd/pke/app/phases/kubeadm/controlplane/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c ControlPlane) WriteKubeadmConfig(out io.Writer, filename string) error {
switch ver.Minor() {
case 12, 13:
conf = kubeadmConfigV1Alpha3()
case 14:
case 14, 15:
conf = kubeadmConfigV1Beta1()
default:
return errors.New(fmt.Sprintf("unsupported Kubernetes version %q for kubeadm", c.kubernetesVersion))
Expand Down
2 changes: 1 addition & 1 deletion cmd/pke/app/phases/kubeadm/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (i *Image) Short() string {

func (i *Image) RegisterFlags(flags *pflag.FlagSet) {
// Kubernetes version
flags.String(constants.FlagKubernetesVersion, "1.14.0", "Kubernetes version")
flags.String(constants.FlagKubernetesVersion, "1.14.3", "Kubernetes version")
// Image repository
flags.String(constants.FlagImageRepository, "banzaicloud", "Prefix for image repository")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pke/app/phases/kubeadm/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *Node) Short() string {

func (n *Node) RegisterFlags(flags *pflag.FlagSet) {
// Kubernetes version
flags.String(constants.FlagKubernetesVersion, "1.14.0", "Kubernetes version")
flags.String(constants.FlagKubernetesVersion, "1.14.3", "Kubernetes version")
// Kubernetes network
flags.String(constants.FlagPodNetworkCIDR, "", "range of IP addresses for the pod network on the current node")
// Pipeline
Expand Down
4 changes: 3 additions & 1 deletion cmd/pke/app/phases/kubeadm/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const (

func Reset(out io.Writer) error {
// kubeadm reset --force
_, _ = fmt.Fprintln(out, "Resetting kubeadm...")
_, _ = fmt.Fprintln(out, "")
_, _ = fmt.Fprintln(out, "================================================================================")
_, _ = fmt.Fprintln(out, "Resetting kubeadm changes...")
err := runner.Cmd(out, cmdKubeadm, "reset", "--force", "--cri-socket=unix:///run/containerd/containerd.sock").CombinedOutputAsync()
if err != nil {
return err
Expand Down
Loading

0 comments on commit a670940

Please sign in to comment.