All good comments, but require a bit of context.
Here are the full verses you reference with additional verses for the sake of context:
John 20:17
17 “Don’t cling to me,” Jesus said, “for I haven’t yet ascended to the Father. But go find my brothers and tell them, ‘I am ascending to my Father and your Father, to my God and your God.’”
Jesus Christ is the incarnate Son of God. He is the second person of the Trinity that has been eternally present with the Father and Spirit. Jesus' hypostatic nature is divided into his divine essence and his incarnate, human essence. He is fully God and was fully man at the same time. God self-limted the Sonship essence of himself into that of a man on earth so that he may become the ultimate, perfect sacrifice for us...God can't die, but a man can. As a man he hungered, thirsted, worked, sweated, was tempted, worshipped the Father (from whom he drew divine strength), his knowledge was limited (as a man he didn’t know the hour of his return, didn’t know the name of demons possessing others, etc…), his grew in knowledge as a man, he prayed to the Father for strength and guidance, etc....he was man (a perfect, sinless man), but also God. Why would God pray to himself? He did so as an example for us and because he was temporarily a man with all physical limitations therein. He drew strength from his divine Fatherly essence. Christ wasn’t play-acting either while on earth as a man, he was God that became man and as such he functioned as a man both for his own survival and as an example for all of us. When Christ indicates that he is returning to the Father he’s doing exactly that….returning to the Father from which he came and returning to his divine, Sonship essence of God. God is one and there is only one God and his nature is divided into three in Father, Son and Spirit. All persons/essences serve different functions, but difference in purpose or position (ex: the Father remained in heaven while the Son was a man on earth) does not mean inequality of divinity…that’s a human misconception. Why wasn’t Christ returning to the Holy Spirit? Christ was birthed as a man by the Holy Spirit and was indwelled by the Holy Spirit. As a man the spirit was in him as it is in other followers of Christ.
You can also refer to John chapter 14 in which Christ outlines that if you have seen him, you save seen the Father. Christ indicates that the Father is in him and that he is in the Father. Christ also indicates that he will be returning to the Father who sent him that is greater than him. "Ah! Ah! You see, Jesus isn't God!" No, no, no...God limited the Sonship essense of himself through the power of his Fatherly essence.....God can do that and did do that. When the Son (Christ) says he is returning to the Father who is greater than I he isn't lying, but that reference to greatness is that of location....the Father is in heaven while Son is on Earth. The Father was also temporarily greater in power and scope than the Son while the Son was a man; regardless, that self-limitation does not deny divinity...again, differnence in purpose does not mean difference in divine equality. Chapter 14 then goes on to describe the Holy Spirt coming to replace Christ once his ascends back to the Father and his full divinity as the Son.....Father, Son and Spirit....coequal, coeternal persons/essences of God who is one.
Luke 18:18-21
The Rich Man
18 Once a religious leader asked Jesus this question: “Good Teacher, what should I do to inherit eternal life?”
19 “Why do you call me good?” Jesus asked him. “Only God is truly good. 20 But to answer your question, you know the commandments: ‘You must not commit adultery. You must not murder. You must not steal. You must not testify falsely. Honor your father and mother.”
21 The man replied, “I’ve obeyed all these commandments since I was young.”
The recorded answer of Jesus is a bit puzzling if only verse 19 is considered, but with the added context of verse 18 the rich man approached Christ asking how to attain eternal life, but referred to him as good teacher. Christ doesn’t answer his question immediately concerning eternal life, but first acknowledges the rich man’s description of Christ as “good teacher”. Christ focuses on the adjective “good” and is essentially prefacing his answer by saying that only God is truly good and suggesting to the man that his description of being merely a “good teacher” is insufficient as true goodness is only found in God himself. It was a very sly affirmation of Jesus’ divinity that also forced the man to stop and consider what he was asking of Christ.
John 17
The Prayer of Jesus
17 After saying all these things, Jesus looked up to heaven and said, “Father, the hour has come. Glorify your Son so he can give glory back to you. 2 For you have given him authority over everyone. He gives eternal life to each one you have given him. 3 And this is the way to have eternal life—to know you, the only true God, and Jesus Christ, the one you sent to earth. 4 I brought glory to you here on earth by completing the work you gave me to do. 5 Now, Father, bring me into the glory we shared before the world began.
You can again refer to my answer related to John 20:17.
See, the whole of scripture should be considered...it blends perfectly and cohesively.
God Bless!